<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/dute_favicon_32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/dute_favicon_16x16.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">
  <link rel="manifest" href="/images/manifest.json">
  <meta name="msapplication-config" content="/images/browserconfig.xml">
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta name="google-site-verification" content="mpI5dkydstZXl6UcDCppqktXK0bbvqdZ6LkZ3KNk4Iw">
  <meta name="baidu-site-verification" content="code-a1LksZX2Ds">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"whitestore.top","root":"/","scheme":"Gemini","version":"7.8.0","exturl":true,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="请输入描述信息">
<meta property="og:type" content="article">
<meta property="og:title" content="【Activity】从零开始到掌握工作流开发业务代码">
<meta property="og:url" content="https://whitestore.top/2023/07/09/activitystudy/index.html">
<meta property="og:site_name" content="爱看书的阿东">
<meta property="og:description" content="请输入描述信息">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230417143259.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230417143324.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230418165217.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230418173615.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230418165556.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230418180558.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230418180901.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230418164742.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230414120549.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230414160845.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230414161927.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230414161755.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/image-20230615213335948.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230208163649.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230208164011.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230208163944.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230208163929.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230206183448.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230204095247.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230210150746.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230423153805.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424150457.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230423164223.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230423164546.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230423164633.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424151054.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230210151955.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230210145809.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230210151753.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230423155906.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424142300.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424143929.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424144024.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424150040.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424150149.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424152125.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424153712.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424160557.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424160638.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424160915.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424161449.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230425172943.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230425172958.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230425174124.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230425174513.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230425174456.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230425174234.png">
<meta property="og:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424104731.png">
<meta property="article:published_time" content="2023-07-09T03:18:59.000Z">
<meta property="article:modified_time" content="2023-07-09T13:31:07.288Z">
<meta property="article:author" content="阿东">
<meta property="article:tag" content="请输入关键字（英文逗号分隔多个关键字）">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230417143259.png">

<link rel="canonical" href="https://whitestore.top/2023/07/09/activitystudy/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>【Activity】从零开始到掌握工作流开发业务代码 | 爱看书的阿东</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="爱看书的阿东" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">爱看书的阿东</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">赐他一块白色石头，石头上写着新名</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-sitemap">

    <a href="/sitemap.xml" rel="section"><i class="fa fa-fw fa-sitemap"></i>站点地图</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    

  <span class="exturl github-corner" data-url="aHR0cHM6Ly9naXRodWIuY29tL2xhenlUaW1lcw==" title="Follow me on GitHub" aria-label="Follow me on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></span>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://whitestore.top/2023/07/09/activitystudy/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="阿东">
      <meta itemprop="description" content="随遇而安">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="爱看书的阿东">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          【Activity】从零开始到掌握工作流开发业务代码
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2023-07-09 11:18:59 / 修改时间：21:31:07" itemprop="dateCreated datePublished" datetime="2023-07-09T11:18:59+08:00">2023-07-09</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Activity/" itemprop="url" rel="index"><span itemprop="name">Activity</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2023/07/09/activitystudy/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2023/07/09/activitystudy/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>57k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>52 分钟</span>
            </span>
            <div class="post-description">请输入描述信息</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="【Activity】从零开始到掌握工作流开发业务代码"><a href="#【Activity】从零开始到掌握工作流开发业务代码" class="headerlink" title="【Activity】从零开始到掌握工作流开发业务代码"></a>【Activity】从零开始到掌握工作流开发业务代码</h1><p>#Activity #工作流</p>
<h1 id="目录"><a href="#目录" class="headerlink" title="目录"></a>目录</h1><p>[Toc]</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230417143259.png" alt="工作流"></p>
<a id="more"></a>

<h1 id="引言"><a href="#引言" class="headerlink" title="引言"></a>引言</h1><p>本文算是自己从零边研究边实践捣鼓到业务上线后全方位补充的一个笔记，对于技术人员推荐直接从<strong>第七章技术选型</strong>开始阅读，前面的理论部分基本是个人搜集的一些网络资料和个人理解笔记，对于使用工作流实现功能没有任何影响。</p>
<p>再次强调，本文非常非常长，请读者按需观看。</p>
<h1 id="一、工作流术语定义"><a href="#一、工作流术语定义" class="headerlink" title="一、工作流术语定义"></a>一、工作流术语定义</h1><h2 id="1-1-基本定义"><a href="#1-1-基本定义" class="headerlink" title="1.1 基本定义"></a>1.1 基本定义</h2><p>Georgakopoulos（乔治亚 * 科普洛斯） 给出的工作流定义是：<strong>工作流是将一组任务组织起来以完成某个经营过程，定义了任务的触发顺序和触发条件，每个任务可以由一个或多个软件系统完成， 也可以由一个或一组人完成，还可以由一个或多个人与软件系统协作完成。</strong></p>
<p>工作流实现了一整套流程内部自动完成的技术，可以屏蔽掉一些繁琐流程的业务进行简化。如果你的业务中没有工作流技术应用，那么完全可以关闭本文然后去刷刷视频干点别的。</p>
<h2 id="1-2-相关术语"><a href="#1-2-相关术语" class="headerlink" title="1.2 相关术语"></a>1.2 相关术语</h2><p>下面工作流程的术语定义。</p>
<table>
<thead>
<tr>
<th>术语</th>
<th>含义</th>
<th>不恰当比喻</th>
</tr>
</thead>
<tbody><tr>
<td><strong>工作流</strong></td>
<td>工作从开始到完成的过程。包含流程逻辑和路线规则，流程逻辑包含任务的执行顺序，路线规则代表任务执行过程中必须遵守的路线，</td>
<td>一项工作或者任务整体过程</td>
</tr>
<tr>
<td><strong>流程定义</strong></td>
<td>图形的流程定义。代表工作流的流程逻辑元素和它们元素关系。</td>
<td>类似快递的传输路线</td>
</tr>
<tr>
<td><strong>流程实例</strong></td>
<td>也叫工作。流程定义的<strong>运行实例</strong>。</td>
<td>类似正在运行的汽车</td>
</tr>
<tr>
<td><strong>工作流系统</strong></td>
<td>存储流程定义，通过<strong>工作流引擎</strong>组件驱动流程定义进行工作。</td>
<td>类似汽车发动机</td>
</tr>
<tr>
<td><strong>流程定义工具</strong></td>
<td>创建和更改流程定义的工具。可以是一个软件的组件，也可以是独立的应用程序。流程定义的工具具备复用性。</td>
<td>绘制汽车设计图的工具或者软件，可以修改产品设计</td>
</tr>
<tr>
<td><strong>参与者</strong></td>
<td>参与者可以是抽象或者具体的，比如资源集、特定资源、组织单元、角色（一个人在组织内部的作用）、人或系统（自动代理）。</td>
<td>路线上每一个节点的行为</td>
</tr>
<tr>
<td><strong>活动</strong></td>
<td>组成流程定义中的一个<strong>逻辑步骤的任务</strong>。可以是自动的或人工的。常见的自动活动就是截止期限管理，如果到期未完成就自动发送提醒消息。手动则是需要人力驱动系统执行业务规则，比如我们日常生活的报销申请审批。</td>
<td>描述某一项任务的处理细节</td>
</tr>
<tr>
<td><strong>活动所有者</strong></td>
<td>有权宣布活动结束或者把工作流程推动到下一个活动参与者</td>
<td>快递运输过程中的每一个站点如何处理快递</td>
</tr>
<tr>
<td><strong>工作所有者</strong></td>
<td>有权参与实例执行过程的参与者。</td>
<td>类似会议的参与人员，有权参加但是不一定有执行权</td>
</tr>
<tr>
<td><strong>工作项</strong></td>
<td>流程实例中活动的参与者将要执行的工作</td>
<td>比如送货的最后一步需要快递员派送快递到用户手里</td>
</tr>
</tbody></table>
<h2 id="1-3-为什么被叫做流？"><a href="#1-3-为什么被叫做流？" class="headerlink" title="1.3 为什么被叫做流？"></a>1.3 为什么被叫做流？</h2><p>各个节点通过内外部驱动触发引起节点的推进，形成一个流式的状态达到业务终点。比如一次用户查看淘宝商品的费用、一次支付成功后的权益开通、一次用户注册、一次调度任务的运行等，都是可以是一个工作流。</p>
<h2 id="1-4-通俗理解"><a href="#1-4-通俗理解" class="headerlink" title="1.4 通俗理解"></a>1.4 通俗理解</h2><p>通俗理解：<strong>工作流</strong> 抽取了流程（例如：请假、报销、岗位调整等流程）运转过程的共性，将<strong>业务处理</strong>和<strong>流程流转</strong>剥离，减少编码过程中的重复性（审批、驳回、转办、挂起、中止等管理工作）操作，并且实现流程流转去纸质化和可视化的技术。</p>
<h2 id="1-5-生命周期"><a href="#1-5-生命周期" class="headerlink" title="1.5 生命周期"></a>1.5 生命周期</h2><p>一个完整的工作流生命周期主要有5步：</p>
<p>1、<strong>定义</strong>：即流程的定义，所有的流程总是从定义开始。主要任务是收集需求并将其转化为流程定义。</p>
<p>2、<strong>发布</strong>：开发人员将资源打包后在系统平台中发布流程定义，主要任务流程定义文件/自定义表单/任务监听类等。</p>
<p>3、<strong>执行</strong>：具体的流程引擎按照上面定义的流程处理路线来执行业务。</p>
<p>4、<strong>监控</strong>：收集每个任务的结果，将根据不同结果来做处理。</p>
<p>5、<strong>优化</strong>：此时业务流程已经完成，需要的就是优化流程或重新设计等。</p>
<h1 id="二、为什么需要工作流"><a href="#二、为什么需要工作流" class="headerlink" title="二、为什么需要工作流"></a>二、为什么需要工作流</h1><h2 id="2-1-工作流管理系统优势"><a href="#2-1-工作流管理系统优势" class="headerlink" title="2.1 工作流管理系统优势"></a>2.1 工作流管理系统优势</h2><p>1、快速、高效、稳定的流程引擎，引擎支持大并发访问。<br>2、兼具人工和自动流程，具有明显的“中国流程”特色的柔性。<br>3、灵活的部署方式，支持集中部署、分布式部署。<br>4、高效的流程集成、整合框架；同时支持流程开发。<br>5、国内数十个行业，拥有近千个成功的客户案例。</p>
<h2 id="2-2-业务可视化"><a href="#2-2-业务可视化" class="headerlink" title="2.2 业务可视化"></a>2.2 业务可视化</h2><p>举个例子，退款本身非常复杂，运营、产品、技术、财务可能都无法从单一的角色来解释清楚到底退款的整个链路和关键环节，但是通过工作流的方式来呈现，则所有人能快速看到退款到底是个什么样的业务。</p>
<p>通过流程图，我们可以清晰的看到节点之间的变化。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230417143324.png" alt="业务可视化"></p>
<h2 id="2-3-业务可编排"><a href="#2-3-业务可编排" class="headerlink" title="2.3 业务可编排"></a>2.3 业务可编排</h2><p>业务流程的编排在实际的运作过程中可能随时变化，工作流流程具备编排性，可以通过节点快速变化业务流程，可以灵活的增减节点，并且不会对于整个流程产生影响。</p>
<p>另一方面代码的可编排意味着代码复用性可以显著提高，比如上面的增加一个【关闭用户权益】的节点，或者删除【用户消息】，我们只需要修改流程而不需要调整业务代码。</p>
<h2 id="2-4-自动重试"><a href="#2-4-自动重试" class="headerlink" title="2.4 自动重试"></a>2.4 自动重试</h2><p>部分工作流支持持久化和自动重试能力。比如有时候需要在流程里面动态增删节点，但是动态增删节点可能会出现失败的情况，出现这种问题的时候可以通过部分节点重试解决问题。</p>
<h1 id="三、常见开源工作流的对比（国外报告）"><a href="#三、常见开源工作流的对比（国外报告）" class="headerlink" title="三、常见开源工作流的对比（国外报告）"></a>三、常见开源工作流的对比（国外报告）</h1><blockquote>
<p>数据来源：<span class="exturl" data-url="aHR0cHM6Ly93b3JrZmxvd2VuZ2luZS5pby9ibG9nL2phdmEtd29ya2Zsb3ctZW5naW5lcy1jb21wYXJpc29uLw==" title="https://workflowengine.io/blog/java-workflow-engines-comparison/">Java Workflow Engines Comparison<i class="fa fa-external-link"></i></span></p>
</blockquote>
<table>
<thead>
<tr>
<th align="left">Feature</th>
<th>Workflow Server</th>
<th>Activiti</th>
<th>jBPM</th>
<th>Camunda</th>
<th>Copper</th>
</tr>
</thead>
<tbody><tr>
<td align="left">Workflow types（工作流类型）</td>
<td>State machine</td>
<td>State machine</td>
<td>State machine</td>
<td>State machine</td>
<td>State machine</td>
</tr>
<tr>
<td align="left">Supported databases（支持数据库）</td>
<td>MS SQL Server, PostgreSQL, Oracle, MySQL, MongoDB</td>
<td>MS SQL, PostgreSQL, Oracle, MySQL, H2, DB2</td>
<td>db2, derby, h2, hsqldb, mysql, oracle, postgresql, sqlserver</td>
<td>MS SQL, PostgreSQL, Oracle, MySQL, H2, DB2, MariaDB</td>
<td>PostgreSQL, Oracle, MySQL, H2, Apache Cassandra</td>
</tr>
<tr>
<td align="left">Long-running operations（是否支持长期运作）</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td align="left">State persistence（状态持久化）</td>
<td>Serialization type is defined by Persistence Provider. You can easily control and change the settings saving process.</td>
<td>Activiti supports recovery in case of error, and will restart as a transactional state machine at the lowest level.</td>
<td>The runtime state of an executing process can be made persistent, for example, in a database. This allows to restore execution states of all running processes in case of unexpected failure.</td>
<td>Persistence Strategy based on the following concepts - Compact Tables, Deadlock Avoidance, Control Savepoints, Intelligent Caching, True Concurrency.</td>
<td>Not declared</td>
</tr>
<tr>
<td align="left">Versioning &amp; upgrading（版本管理和升级）</td>
<td>The processes that were created before the schema change, work under the old scheme, whereas the scheme of the specific process is updated after calling the appropriate command.</td>
<td>Versioning only</td>
<td>Both</td>
<td>With the use of additional converters</td>
<td>Yes, you can dynamically modify workflows at runtime. As soon as you save the changed code, Copper compiles it automatically and loads it.</td>
</tr>
<tr>
<td align="left">Scheme format（底层存储格式）</td>
<td>The proprietary format based on XML. Import and export to BPMN2 starting with version 2.1.</td>
<td>BPMN2</td>
<td>BPMN2</td>
<td>BPMN2</td>
<td>Process scheme is declared as Java-code</td>
</tr>
<tr>
<td align="left">Installing the process in an arbitrary state（是否支持任意状态兼容工作流）</td>
<td>Yes, by calling a single method</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td align="left">Obtaining a list of available states for the current process（是否支持获得当前进程的可用状态列表）</td>
<td>Yes, by calling a single method</td>
<td>Yes, by calling a single method</td>
<td>No</td>
<td>No</td>
<td>Unknown</td>
</tr>
<tr>
<td align="left">Built-in authorization of access to external actions (commands) for the workflow（是否允许外部访问内部流程）</td>
<td>Yes</td>
<td>No</td>
<td>No</td>
<td>No</td>
<td>No</td>
</tr>
<tr>
<td align="left">Timers and delays（是否支持计时和延迟）</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr>
<td align="left">Obtaining a list of available external actions for the current process（获得当前进程的可用外部行动的列表）</td>
<td>Yes, by calling a single method</td>
<td>No</td>
<td>No</td>
<td>No</td>
<td>No</td>
</tr>
<tr>
<td align="left">Simulated process execution（是否支持流程单元测试）</td>
<td>Yes, this mode is called Pre-Execution.</td>
<td>No</td>
<td>No</td>
<td>No</td>
<td>No</td>
</tr>
<tr>
<td align="left">Modifying schemes at runtime（是否支持在运行时改变流程）</td>
<td>Yes, built in.</td>
<td>No</td>
<td>No</td>
<td>No</td>
<td>Yes</td>
</tr>
<tr>
<td align="left">Obtaining process lists for Inbox and Outbox folders（获取收件箱和发件箱文件夹的进程列表）</td>
<td>Yes</td>
<td>No</td>
<td>No</td>
<td>No</td>
<td>No</td>
</tr>
</tbody></table>
<h1 id="四、工作流使用场景"><a href="#四、工作流使用场景" class="headerlink" title="四、工作流使用场景"></a>四、工作流使用场景</h1><h2 id="4-1-领域业务高复杂度"><a href="#4-1-领域业务高复杂度" class="headerlink" title="4.1 领域业务高复杂度"></a>4.1 领域业务高复杂度</h2><p>比如进销存、CRM、订单管理等具备一定的领域复杂度的业务，可以用工作流模式，来实现业务的可视化。</p>
<h2 id="4-2-多节点、长链路"><a href="#4-2-多节点、长链路" class="headerlink" title="4.2 多节点、长链路"></a>4.2 多节点、长链路</h2><p>比如业务流转的过程要经过多个人，但是每个节点都需要独立，这种就比较适合无状态的内存工作流。</p>
<p>多节点比如一个审批任务需要同时转交给多个人审批并且同时通过才能进行下一步，长链路则是遇到审批过程需要多于5层以上的时候非常方便。</p>
<h2 id="4-3-状态持久化和自动重试"><a href="#4-3-状态持久化和自动重试" class="headerlink" title="4.3 状态持久化和自动重试"></a>4.3 状态持久化和自动重试</h2><p>例如订单支付成功后，驱动下游业务系统开通、发送用户提醒消息、扣减库存等异步流程节点，需要持久化每个节点的执行状态。</p>
<h1 id="五、工作流分类"><a href="#五、工作流分类" class="headerlink" title="五、工作流分类"></a>五、工作流分类</h1><p>那么工作流该如何分类，如何抽象和归类自身的业务？</p>
<p>我们可以把工作流大致分类为：<strong>内存工作流、状态机工作流、人工工作流</strong>。</p>
<h2 id="5-1-内存工作流"><a href="#5-1-内存工作流" class="headerlink" title="5.1 内存工作流"></a>5.1 内存工作流</h2><p>内存工作流是最简单的工作流，不需要持久化并且没有状态，类似代码的业务逻辑流转，因为所有的逻辑都是内存完成，业务本身是无状态的，所以不需要持久化。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230418165217.png" alt="内存工作流"></p>
<p>内存工作流也可以用业务编码完成，可以使得业务可视化，视图可以看出整个业务是如何流转的，业务工作流使的每个节点能够最大程度的复用。</p>
<h2 id="5-2-状态机工作流"><a href="#5-2-状态机工作流" class="headerlink" title="5.2 状态机工作流"></a>5.2 状态机工作流</h2><p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230418173615.png" alt="状态机工作流"></p>
<p>当需要自动重试节点操作的时候需要用到状态机，状态机可以看作是内存工作流的升级。一般的工作流引擎提供了默认集成的调度框架可以低成本的实现自动调度。</p>
<p>当某个节点处理失败后，节点置为异常状态，工作流调度模块会拉取失败的节点，继续按照工作流预定义的流程重试， 直到重试到指定的配置次数后，将整个流程置为执行失败，此时需要人工介入。</p>
<h2 id="5-3-人工工作流"><a href="#5-3-人工工作流" class="headerlink" title="5.3 人工工作流"></a>5.3 人工工作流</h2><p>人工工作流使用场景最为广泛和频繁也最贴合实际生活。人工工作流也叫做<strong>外部触发驱动工作流</strong>，至少是存在一个或者多个节点是待外部确认才能推进整体业务流程。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230418165556.png" alt="人工工作流"></p>
<p>人工工作流最大特点是状态流转的手动触发机制，这种拦截触发到下一流程的机制可以适用于大部分业务。比如业务流程依赖审批的，比如退款流程，需要负责人审批通过后才能进行打款。</p>
<p>因为人工工作流需要手动触发才能进行下一步的流转，设计会稍微复杂一些，分了多个表。</p>
<ul>
<li><strong>bpm_workflow_instance</strong> ： 工作流实例表，表示一个具体执行的业务流；</li>
<li><strong>bpm_task_instance</strong> ： 任务实例，将工作流的每个节点当做一个任务实例存储下来，描述一个工作流实例里 每个节点的具体状态；</li>
<li><strong>bpm_param_instance</strong> ： 参数实例，工作流或者任务实例的上下文入参快照；</li>
<li><strong>bpm_timer_task</strong>：处理定时任务表，比如人工节点未审批自动超期等 bpm_sequence ：生成上述四个表的主键ID表；</li>
</ul>
<h1 id="六、工作流设计准则"><a href="#六、工作流设计准则" class="headerlink" title="六、工作流设计准则"></a>六、工作流设计准则</h1><h2 id="6-1-工作流设计准则"><a href="#6-1-工作流设计准则" class="headerlink" title="6.1 工作流设计准则"></a>6.1 工作流设计准则</h2><h3 id="6-1-1-角色"><a href="#6-1-1-角色" class="headerlink" title="6.1.1 角色"></a>6.1.1 角色</h3><ol>
<li>发起人：发起人是一个流程的主要关系者，是最关心审批进展的人，发起人完成的主要是事务性、操作性的工作。从发起人的角度来说，在创建完审批事项后，还需要完善相关信息、催促审批人及时处理、跟进驳回修改意见、重新提交。</li>
<li>审批人：审批人需要完成流程中的决策性工作，因此在审批人的视角，内容和操作都应该尽量精简：只展现出最重要的信息，避免过多信息影响判断，只进行必要操作，不能有过多选择或操作，且需要保留审批历史，以便追溯。</li>
</ol>
<h3 id="6-1-2-内容：提炼最小集合"><a href="#6-1-2-内容：提炼最小集合" class="headerlink" title="6.1.2 内容：提炼最小集合"></a>6.1.2 内容：提炼最小集合</h3><p>内容设计要点在于尽可能精炼内容，要注意保留必要内容，但凡是系统可自动获取的数据，就尽量避免发起人手动输入预置的常用内容，用选择的方式替代输入的，同时也能提高内容规范性。</p>
<h3 id="6-1-3-根据业务设计流程"><a href="#6-1-3-根据业务设计流程" class="headerlink" title="6.1.3 根据业务设计流程"></a>6.1.3 根据业务设计流程</h3><ol>
<li>自主选定审批人流程：这是一种比较轻量、灵活的审批流程形式，适用没有标准化工作流程的业务场景。当流程发起人发起审批事项时，需要自动选择下一个环节的审批人，而下一个环节的审批人审批通过后，可以选择继续流转到再下一人，也可结束这个流程。</li>
<li>串行流程：只有当每个环节的审批人通过流程后，才会进入到下一环节。每个环节的驳回，可以根据业务需要，设计成驳回到发起人、驳回到上一环节或回到指定环节重新审批，或兼而有之，作为选项供审批人选择。</li>
<li>并行流程：并行流程是审批环节需要多人（角色）审批同意才算通过。任意一人审批通过即进入下一环节 &amp; 必须所有人审批通过才进入下一环节。</li>
<li>条件触发流程：例如金额低于 1 万元由财务总监审批通过后即结束，金额在 1 万元以上则由副总裁审批通过后即结束。</li>
<li>混合流程：以上述金额审批为例，若金额低于 1 万元，由财务审批通过后即结束；金额在 1 万元到 10 万元的，需要先由财务审批，之后交由副总裁审批通过后即结束；金额高于 10 万元的，需要由董事长和总裁一同审批通过后才结束。</li>
</ol>
<h3 id="6-1-4-审批动作确定"><a href="#6-1-4-审批动作确定" class="headerlink" title="6.1.4 审批动作确定"></a>6.1.4 审批动作确定</h3><ol>
<li>通过。通过原因是否必填需要根据业务实际情况决定，通过之后流程会继续流转到下一个节点。</li>
<li>驳回修改。驳回原因一般需要设定成必填项，否则发起人或前一审批环节的参与者将无法获取被驳回的理由、和修改建议。驳回可以设计为三种：驳回到发起人 &amp; 驳回上一环节 &amp; 驳回到选定的之前的某个审批环节。</li>
<li>重新提交。通常审批人审批重新提交的内容时，需要附带上一次驳回的原因。</li>
<li>取消。可选操作，一般由发起人而不是审批人取消，原因是审批人只关心是否通过还是驳回，取消和驳回容易混淆。</li>
</ol>
<h3 id="6-1-5-权限"><a href="#6-1-5-权限" class="headerlink" title="6.1.5 权限"></a>6.1.5 权限</h3><p>权限体系的设计是一个大工程，在审批流程中，采用基于角色的访问控制体系（RBAC）是一个不错的选择。基于角色的访问控制体系，包括<strong>用户、角色、目标、操作、许可权</strong>五个基本数据元素，具体内容分为可区分为功能权限和数据权限。</p>
<p>这里不过多扩展权限设计，在工作流设计中权限主要关注什么人可以发起审批，功能权限在拥有对应权限的角色可见，数据权限则通常是发起人和审批人共同可见。</p>
<h3 id="6-1-6-配置和扩展性"><a href="#6-1-6-配置和扩展性" class="headerlink" title="6.1.6 配置和扩展性"></a>6.1.6 配置和扩展性</h3><p>一般针对企业开发后台系统的灵活性相对较少，而面向多个企业的商业化的系统则灵活性要求高。配置和扩展性通常和业务复杂程度成正比。</p>
<p>配置的灵活性体现在以下方面：</p>
<ul>
<li>审批流程的类型</li>
<li>可修改具体的审批环节</li>
<li>可增删改的各个环节审批人/角色</li>
<li>可配置的审批相关的权限。</li>
</ul>
<h3 id="6-1-7-效率"><a href="#6-1-7-效率" class="headerlink" title="6.1.7 效率"></a>6.1.7 效率</h3><p>工作流的核心目标是提高企业和组织的运行效率，如果线上审批流程效率还不如原来的纸质操作，那这个流程的设计就是失败的，也失去了意义。所以利用工作流提升审批流程效率，要注意尽可能精简审批的操作，做好流程操作的引导。</p>
<h2 id="6-2-流程编排"><a href="#6-2-流程编排" class="headerlink" title="6.2 流程编排"></a>6.2 流程编排</h2><p>流程编码涉及到各个节点的跳转细节。</p>
<p>流程编排的时候需要考虑那些部分需要判断，哪些地方需要进行分支，需要注意失败节点的处理非常重要，同时也要考虑工作流无法往下进行的问题等。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230418180558.png" alt="流程编排"></p>
<h2 id="6-3-异常处理"><a href="#6-3-异常处理" class="headerlink" title="6.3 异常处理"></a>6.3 异常处理</h2><p>一般的工作流引擎工具中就设计了对异常的统一处理方式，下面的代码在也可以参考在日常开发过程中使用。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230418180901.png" alt="异常处理"></p>
<p>以上代码可以看出，工作流基本不处理异常，而是把异常收集到上层应用层进行统一处理。统一处理异常的优点是可以统一工作流节点错误处理方式，还可以打印错误提醒日志，方便快速定位工作流运行期间产生的异常问题。</p>
<h2 id="6-4-工作流问题"><a href="#6-4-工作流问题" class="headerlink" title="6.4 工作流问题"></a>6.4 工作流问题</h2><ol>
<li>常用的bmpn格式就存在较多的问题，底层格式为难懂的XML元素。</li>
<li>图形拖拽不美观、上下文变量设置麻烦、容易出异常未知问题。</li>
<li>始终没有一个非常极致体验的工作流引擎。</li>
<li>引入工作流本身会增加工程难度。</li>
<li>增加学习和使用成本。</li>
</ol>
<h2 id="6-5-不适用场景"><a href="#6-5-不适用场景" class="headerlink" title="6.5 不适用场景"></a>6.5 不适用场景</h2><ol>
<li>简单的业务逻辑，几段代码搞定的，也无需考虑使用工作流。</li>
<li>比较简单的流程定义。</li>
<li>业务比较固定的场景。</li>
</ol>
<h2 id="6-6-工作流业务特点"><a href="#6-6-工作流业务特点" class="headerlink" title="6.6 工作流业务特点"></a>6.6 工作流业务特点</h2><p>特点 ：</p>
<ol>
<li><p>图形化、可视化设计流程图 。</p>
</li>
<li><p>支持各种复杂流程 。</p>
</li>
<li><p>组织结构级处理者指定功能 。</p>
</li>
<li><p>B/S结构，纯浏览器应用 。</p>
</li>
<li><p>强大的安全性特色 。</p>
</li>
<li><p>表单功能强大，扩展便捷 。</p>
</li>
<li><p>灵活的外出、超时管理策略 。</p>
</li>
<li><p>处理过程可跟踪、管理  。</p>
</li>
<li><p>丰富的统计、查询、报表功能 。</p>
</li>
<li><p>与MAIL系统集成。</p>
</li>
</ol>
<h2 id="6-7-工作流思想"><a href="#6-7-工作流思想" class="headerlink" title="6.7 工作流思想"></a>6.7 工作流思想</h2><p><strong>只要采用流程模板+实例化思想都可以认为是工作流</strong>。</p>
<h1 id="七、工作流技术选型"><a href="#七、工作流技术选型" class="headerlink" title="七、工作流技术选型"></a>七、工作流技术选型</h1><p>工作流如果是从零设计非常复杂，这里主要介绍介绍市面上常见的工作流引擎，市面上比较主流的工作流引擎为<strong>osworkflow</strong>、<strong>jbpm</strong>、<strong>activiti</strong>、<strong>flowable</strong>、<strong>camunda</strong>……</p>
<p>其中Jbpm4、Activiti、Flowable、camunda 四个框架同宗同源，祖先都是<strong>Jbpm4</strong>，开发者只要用过其中一个框架，基本上就会用其它三个。</p>
<h2 id="7-1-Osworkflow"><a href="#7-1-Osworkflow" class="headerlink" title="7.1 Osworkflow"></a>7.1 Osworkflow</h2><p>Osworkflow是一个轻量化的流程引擎，基于状态机机制，数据库表很少，Osworkflow提供的工作流构成元素有：步骤（step）、条件（conditions）、循环（loops）、分支（spilts）、合并（joins）等，<strong><em><em>但不支持会签、跳转、退回、加签等这些操作</em></em></strong>，需要自己扩展开发，有一定难度，如果流程比较简单，osworkflow是不错的选择。</p>
<p>文档地址：<span class="exturl" data-url="aHR0cHM6Ly9kb2NzLmh1aWhvby5jb20vb3N3b3JrZmxvdy9vc3dvcmtmbG93LWRldmVsb3Blci1ndWlkZS5wZGY=" title="https://docs.huihoo.com/osworkflow/osworkflow-developer-guide.pdf">https://docs.huihoo.com/osworkflow/osworkflow-developer-guide.pdf<i class="fa fa-external-link"></i></span></p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230418164742.png" alt="osworkflow"></p>
<p>概括：轻量化流程引擎，基于状态机的机制进行工作，因为轻量级所以数据库内容比较少，比较适合简单的业务。</p>
<p>Osworkflow提供的工作流构成元素</p>
<ul>
<li>步骤（step）</li>
<li>条件（conditions）</li>
<li>循环（loops）</li>
<li>分支（spilts）</li>
<li>合并</li>
</ul>
<p>不支持的操作</p>
<ul>
<li>回签</li>
<li>跳转 </li>
<li>退回</li>
<li>加签</li>
</ul>
<p>特点：因为轻量化，所以有些功能需要自己开发，针对一些简单流程的快速开发是比较好的选择。</p>
<h2 id="7-2-JBPM"><a href="#7-2-JBPM" class="headerlink" title="7.2 JBPM"></a>7.2 JBPM</h2><p>官网：<span class="exturl" data-url="aHR0cHM6Ly93d3cuamJwbS5vcmcv" title="https://www.jbpm.org/">jBPM - Open Source Business Automation Toolkit - jBPM Business Automation Toolkit<i class="fa fa-external-link"></i></span></p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230414120549.png" alt="jbpm"></p>
<p>JBPM也是老牌软件，由JBoss公司开发，目前最高版本JPBM7，需要注意从JBPM5 开始就已经和前面的版本断层了（5开始基于<code>Drools Flow</code>，也叫做规则引擎），而大部分网络资料都是基于JBPM 4的，所以<strong>强烈不建议</strong>选择jBPM5以后版本，也不推荐用JBPM，比较容易踩坑。</p>
<blockquote>
<p>JBPM 的规则引擎引入不仅没有降低工作流的理解和使用成本，反而导致结构设计混乱并且臃肿不堪。</p>
</blockquote>
<h2 id="7-3-Activiti"><a href="#7-3-Activiti" class="headerlink" title="7.3 Activiti"></a>7.3 Activiti</h2><p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230414160845.png" alt="activity"></p>
<p>Activiti 是自带Spring官方集成支持的工作流引擎，如果是SpringBoot开发可以作为备选方案。</p>
<p>需要注意Activity的背景比较复杂，最高版本activiti 7，此外版本选择上比较复杂，有activiti5、activiti6、activiti7几个主流版本，需要谨慎考量。</p>
<p>我们借着Activity扩展下相关历史。</p>
<p>activiti5 和 activiti6 的核心leader是<strong>Tijs Rademakers</strong>（蒂亚斯-拉德梅克），由于团队内部分歧，在2017年时 <strong>Tijs Rademakers</strong>离开团队，创建了后来的 flowable, activiti6 以及activiti5 代码已经交接给了 Salaboy 团队, activiti6 以及 activiti5 的代码官方已经暂停维护了, 目前主流版本为Activiti7，但是activiti7内核使用的还是activiti6，并没有为引擎注入更多的新特性，更多是对于云服务的一系列支持。</p>
<p>根据上面所述，我们得知Activiti 有三个版本：<strong>activiti5</strong>、<strong>activiti6</strong>、<strong>activiti7</strong>。默认建议选择 Activiti7 的版本，Activiti 的独立起初是为了替代JBPM的，但是后来开发团队内部分歧，主创因为意见不和，离职之后加入其他团队捣鼓出了Flowable。由此可见Flowable必定把Activity以及JBPM带来的的历史遗留问题一一解决，所以也是比较推荐的工作流引擎选择。</p>
<blockquote>
<p>说白了捣鼓来捣鼓去的都是同一帮人，和Java日志的历史有点像。</p>
</blockquote>
<p>官网：<span class="exturl" data-url="aHR0cHM6Ly93d3cuYWN0aXZpdGkub3JnLw==" title="https://www.activiti.org/">Open Source Business Automation | Activiti<i class="fa fa-external-link"></i></span></p>
<h2 id="7-4-Flowable"><a href="#7-4-Flowable" class="headerlink" title="7.4 Flowable"></a>7.4 Flowable</h2><p>Flowable 基于activiti6衍生出来的版本，目前最新版本是v6.6.0，开发团队是从activiti中分裂出来的，修复了一众activiti6的bug，并在其基础上研发了DMN支持，BPEL支持等等，相对开源版其商业版的功能会更强大。</p>
<p>2016 年 10 月，Activiti 工作流引擎的主要开发者离开 Alfresco 公司，并在 Activiti 分支基础上开启了 Flowable 开源项目。基于 Activiti v6 beta4 发布的第一个 Flowable release 版本为6.0 。</p>
<p>Flowable 也是目前比较主流的一种工作流引擎实现。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230414161927.png" alt="flowable"></p>
<p>Flowable在后续极力发展商业化，导致开源版本的更新比较落后。</p>
<h2 id="7-5-Camunda"><a href="#7-5-Camunda" class="headerlink" title="7.5 Camunda"></a>7.5 Camunda</h2><p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230414161755.png" alt="camunda"></p>
<p>Camunda基于Activiti5，所以其保留了PVM，最新版本Camunda7.15，保持每年发布2个小版本的节奏，开发团队又是从activiti中分裂出来的，发展轨迹与Flowable相似，同时也提供了商业版，不过对于一般企业应用，开源版本也足够了。</p>
<blockquote>
<p>黄埔军校：Activity</p>
</blockquote>
<p>选择Camunda的理由</p>
<p>（1）通过压力测试验证Camunda BPMN引擎性能和稳定性更好。</p>
<p>（2）功能比较完善，除了BPMN，Camunda还支持企业和社区版本中的CMMN（案例管理）和DMN（决策自动化）。Camunda不仅带有引擎，还带有非常<span class="exturl" data-url="aHR0cHM6Ly9saW5rLnpoaWh1LmNvbS8/dGFyZ2V0PWh0dHBzJTNBLy9jYW11bmRhLm9yZy9mZWF0dXJlcy8=" title="https://link.zhihu.com/?target=https%3A//camunda.org/features/">强大的工具，<i class="fa fa-external-link"></i></span>用于建模，任务管理，操作监控和用户管理，所有这些都是开源的。</p>
<p>官方网站：<span class="exturl" data-url="aHR0cHM6Ly9kb2NzLmNhbXVuZGEub3JnL21hbnVhbC83LjE1Lw==" title="https://docs.camunda.org/manual/7.15/">https://docs.camunda.org/manual/7.15/<i class="fa fa-external-link"></i></span></p>
<h2 id="7-6-Easy-flow"><a href="#7-6-Easy-flow" class="headerlink" title="7.6 Easy-flow"></a>7.6 Easy-flow</h2><p>码云上开源的流程设计器，没有社区和用户使用反馈支持，不过多介绍。</p>
<blockquote>
<p>如果是深入工作流引擎底层设计本身是一个不错的学习资料。</p>
</blockquote>
<p><span class="exturl" data-url="aHR0cHM6Ly9saW5rLnpoaWh1LmNvbS8/dGFyZ2V0PWh0dHBzJTNBLy9naXRlZS5jb20veGlhb2thMjAxNy9lYXN5LWZsb3clM0ZfZnJvbSUzRGdpdGVlX3NlYXJjaA==" title="https://link.zhihu.com/?target=https%3A//gitee.com/xiaoka2017/easy-flow%3F_from%3Dgitee_search">https://link.zhihu.com/?target=https%3A//gitee.com/xiaoka2017/easy-flow%3F_from%3Dgitee_search<i class="fa fa-external-link"></i></span></p>
<h2 id="7-7-compileflow"><a href="#7-7-compileflow" class="headerlink" title="7.7 compileflow"></a>7.7 compileflow</h2><p>淘宝开源的工作流引擎之一。算是国内最大的开源工作流引擎，但是存在一些“致命伤”，<strong>compileflow原生只支持淘宝BPM规范</strong>，为兼容BPMN 2.0规范，做了一定适配，但<strong>仅支持部分BPMN 2.0元素</strong>，如需其他元素支持，可在原来基础上扩展。</p>
<p>github地址：<span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2FsaWJhYmEvY29tcGlsZWZsb3c=" title="https://github.com/alibaba/compileflow">alibaba/compileflow: 🎨 core business process engine of Alibaba Halo platform, best process engine for trade scenes. | 一个高性能流程编排引擎 (github.com)<i class="fa fa-external-link"></i></span></p>
<p>下面是官方的README介绍：</p>
<p>compileflow IDEA 设计插件:  <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2NvbXBpbGVmbG93L2NvbXBpbGVmbG93LWRlc2lnbmVyLXVwZ3JhZGU=" title="https://github.com/compileflow/compileflow-designer-upgrade">https://github.com/compileflow/compileflow-designer-upgrade<i class="fa fa-external-link"></i></span></p>
<p><code>compileflow</code>是一个非常轻量、高性能、可集成、可扩展的流程引擎。</p>
<p><code>compileflow Process</code>引擎是淘宝工作流<code>TBBPM</code>引擎之一，是专注于纯内存执行，无状态的流程引擎，通过将流程文件转换生成<code>java</code>代码编译执行，简洁高效。当前是阿里业务中台交易等多个核心系统的流程引擎。</p>
<p><code>compileflow</code>能让开发人员通过流程编辑器设计自己的业务流程，将复杂的业务逻辑可视化，为业务设计人员与开发工程师架起了一座桥梁。</p>
<h2 id="7-8-推荐组合"><a href="#7-8-推荐组合" class="headerlink" title="7.8 推荐组合"></a>7.8 推荐组合</h2><p>初学者个人比较推荐 <strong>Activity7 + IDEA</strong> 的插件组合，最方便上手，Activity 天然支持Spring框架，自动生成的表数量仅为28张，相比 Flowable 的 70多张表而言学习成本算是最低的，并且从上面的介绍可以看出，其他很多对标竞品的开发团队都是从Activity<strong>黄埔军校</strong>毕业的。 </p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/image-20230615213335948.png" alt=""></p>
<p>最为关键的是，这个组合网上还可以查到不少资料和实战…..</p>
<h1 id="八、流程设计器选型"><a href="#八、流程设计器选型" class="headerlink" title="八、流程设计器选型"></a>八、流程设计器选型</h1><h3 id="8-1-bpmn-js"><a href="#8-1-bpmn-js" class="headerlink" title="8.1 bpmn-js"></a>8.1 bpmn-js</h3><p>bpmn-js 是 BPMN 2.0 渲染工具包和 Web 模型，bpmn-js 正在努力成为 <span class="exturl" data-url="aHR0cHM6Ly9saW5rLnpoaWh1LmNvbS8/dGFyZ2V0PWh0dHAlM0EvL3d3dy5vc2NoaW5hLm5ldC9wL2NhbXVuZGE=" title="https://link.zhihu.com/?target=http%3A//www.oschina.net/p/camunda">Camunda BPM<i class="fa fa-external-link"></i></span> 的一部分。</p>
<p>官方网站：<span class="exturl" data-url="aHR0cHM6Ly9saW5rLnpoaWh1LmNvbS8/dGFyZ2V0PWh0dHBzJTNBLy9icG1uLmlvLw==" title="https://link.zhihu.com/?target=https%3A//bpmn.io/">https://bpmn.io/<i class="fa fa-external-link"></i></span></p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230208163649.png" alt="bpmn"></p>
<h3 id="8-2-mxGraph"><a href="#8-2-mxGraph" class="headerlink" title="8.2 mxGraph"></a>8.2 mxGraph</h3><p>mxGraph是一个强大的JavaScript流程图前端库，可以快速创建交互式图表和图表应用程序，国内外著名的<span class="exturl" data-url="aHR0cHM6Ly9saW5rLnpoaWh1LmNvbS8/dGFyZ2V0PWh0dHBzJTNBLy93d3cucHJvY2Vzc29uLmNvbS8=" title="https://link.zhihu.com/?target=https%3A//www.processon.com/">ProcessOne<i class="fa fa-external-link"></i></span>和<span class="exturl" data-url="aHR0cHM6Ly9saW5rLnpoaWh1LmNvbS8/dGFyZ2V0PWh0dHBzJTNBLy93d3cuZHJhdy5pby8=" title="https://link.zhihu.com/?target=https%3A//www.draw.io/">draw.io<i class="fa fa-external-link"></i></span>都是使用该库创建的强大的在线流程图绘制网站。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230208164011.png" alt="mxGraph"></p>
<h2 id="8-3-Activiti-Modeler"><a href="#8-3-Activiti-Modeler" class="headerlink" title="8.3 Activiti-Modeler"></a>8.3 Activiti-Modeler</h2><p>Activiti 的旧版本中存在web版流程设计器，名字叫做Activiti-explorer，优点是集成简单，开发工作量小，缺点是界面不美观，用户体验差。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230208163944.png" alt="activity-modeler"></p>
<h2 id="8-4-Flowable-Modeler"><a href="#8-4-Flowable-Modeler" class="headerlink" title="8.4 Flowable-Modeler"></a>8.4 Flowable-Modeler</h2><p>Flowable 开源版本中带了web版流程设计器，展示风格和功能基本跟Activiti-Modeler一样，优点是集成简单，开发工作量小，缺点是界面不美观，用户体验差。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230208163929.png" alt="flowable-modeler"></p>
<h2 id="8-5-IDEA-Activiti-BPMN-插件"><a href="#8-5-IDEA-Activiti-BPMN-插件" class="headerlink" title="8.5 IDEA Activiti BPMN 插件"></a>8.5 IDEA Activiti BPMN 插件</h2><p>个人学习工作流模型图设计比较推荐使用 Idea 的插件，最新版本的插件已经被叫做<code>activiti BPMN visualizer</code>。开发人员可以借助此插件熟悉流程图的绘画过程。</p>
<p>PS：Activity 支持 BPMN2 规范，可以兼容大部分开源工作流框架使用。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230206183448.png" alt="idea activity bpmn"></p>
<h2 id="8-6-logicFlow"><a href="#8-6-logicFlow" class="headerlink" title="8.6 logicFlow"></a>8.6 logicFlow</h2><p>滴滴开发的流程设计器：logicFlow，支持自定义优秀，并可以将bpmn-js以插件形式集成进去，但是不推荐生产使用，比较适合作为国内优秀学习资料的范本。</p>
<p>文档地址：<span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2RpZGkvTG9naWNGbG93" title="https://github.com/didi/LogicFlow">https://github.com/didi/LogicFlow<i class="fa fa-external-link"></i></span></p>
<h1 id="九、Activity-详解"><a href="#九、Activity-详解" class="headerlink" title="九、Activity 详解"></a>九、Activity 详解</h1><h2 id="9-1-为什么要使用-Activity？"><a href="#9-1-为什么要使用-Activity？" class="headerlink" title="9.1 为什么要使用 Activity？"></a>9.1 为什么要使用 Activity？</h2><p>Activiti是一个轻量级的工作流和业务流程管理（BPM）平台，面向业务人员，开发人员和系统管理员，核心是用于Java的的BPMN 2流程引擎。</p>
<ol>
<li>开源可参考项目比较多：github和gitee上有非常多的成熟案例可以学习。</li>
<li>Activiti 支持启动引擎后随时热部署。JBPM存在一个软肋，RuntimeService只能在启动的时候指定bpmn资源，一旦启动后便不再能够去更新或者增加bpmn了，这会导致我们系统集成的困难</li>
<li>Activity本身开源。开源意味着可以通过社区和其他人的实践案例解决使用问题上的疑难杂症。</li>
<li>Activiti依赖的第三方jar包相对较少。</li>
<li>Activiti拥有更友好的用户体验。Activiti则更贴近实际的应用场景，将流程设置为开始节点和结束节点，人工任务提供了表单设置，用户可以设置字段名称，字段类型。</li>
<li>自带<strong>Spring</strong> 集成 ，同时也集成了 <strong>Spring Security</strong> 框架，也可以认为是<strong>自带权限控制功能</strong>。</li>
<li>API 简洁，开发人员可以快速上手。</li>
<li>Activity 7 没有明显的进步，并且可参考实战案例较少。</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"> <span class="function">TaskQuery <span class="title">taskId</span><span class="params">(String taskId)</span></span>;</span><br><span class="line"><span class="function">TaskQuery <span class="title">taskName</span><span class="params">(String name)</span></span>;</span><br><span class="line"><span class="function">TaskQuery <span class="title">taskNameLike</span><span class="params">(String nameLike)</span></span>;</span><br><span class="line"><span class="function">TaskQuery <span class="title">taskDescription</span><span class="params">(String description)</span></span>;</span><br><span class="line"><span class="function">TaskQuery <span class="title">taskDescriptionLike</span><span class="params">(String descriptionLike)</span></span>;</span><br><span class="line"><span class="function">TaskQuery <span class="title">taskPriority</span><span class="params">(Integer priority)</span></span>;</span><br><span class="line"><span class="function">TaskQuery <span class="title">taskMinPriority</span><span class="params">(Integer minPriority)</span></span>;</span><br><span class="line"><span class="function">TaskQuery <span class="title">taskMaxPriority</span><span class="params">(Integer maxPriority)</span></span>;</span><br><span class="line"><span class="function">TaskQuery <span class="title">taskAssignee</span><span class="params">(String assignee)</span></span>;</span><br><span class="line"><span class="function">TaskQuery <span class="title">taskAssigneeLike</span><span class="params">(String assigneeLike)</span></span>;</span><br><span class="line"><span class="function">TaskQuery <span class="title">taskOwner</span><span class="params">(String owner)</span></span>;</span><br><span class="line"><span class="function">TaskQuery <span class="title">taskOwnerLike</span><span class="params">(String ownerLike)</span></span>;</span><br><span class="line"><span class="function">TaskQuery <span class="title">taskUnassigned</span><span class="params">()</span></span>;</span><br><span class="line"><span class="function">TaskQuery <span class="title">taskUnnassigned</span><span class="params">()</span></span>;</span><br></pre></td></tr></table></figure>

<p>Spring 集成 Activity 官方文档：<span class="exturl" data-url="aHR0cHM6Ly9zcHJpbmcuaW8vYmxvZy8yMDE1LzAzLzA4L2dldHRpbmctc3RhcnRlZC13aXRoLWFjdGl2aXRpLWFuZC1zcHJpbmctYm9vdA==" title="https://spring.io/blog/2015/03/08/getting-started-with-activiti-and-spring-boot">Getting started with Activiti and Spring Boot<i class="fa fa-external-link"></i></span></p>
<blockquote>
<p>Activiti User Guide：<span class="exturl" data-url="aHR0cHM6Ly93d3cuYWN0aXZpdGkub3JnL3VzZXJndWlkZS8jX2ludHJvZHVjdGlvbg==" title="https://www.activiti.org/userguide/#_introduction">Activiti User Guide<i class="fa fa-external-link"></i></span></p>
</blockquote>
<h2 id="9-2-Activity-特点"><a href="#9-2-Activity-特点" class="headerlink" title="9.2 Activity 特点"></a>9.2 Activity 特点</h2><p>1、数据持久化：Activiti设计思想是简洁与快速。</p>
<p>2、引擎Service接口：Activiti引擎提供了七大Service接口，都是通过ProcessEngine获取，同时支持链式API编程风格。</p>
<table>
<thead>
<tr>
<th>Service接口</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>RepositoryService</td>
<td>流程仓库Service，用于管理流程仓库，如：部署、删除、读取流程资源</td>
</tr>
<tr>
<td>IdentifyService</td>
<td>身份Service，可管理和查询用户、组之间的关系</td>
</tr>
<tr>
<td>RuntimeService</td>
<td>运行时Service，处理所有正在运行的任务和流程实例等</td>
</tr>
<tr>
<td>TaskService</td>
<td>任务Service，用于管理查询任务，如签收、办理、指派等</td>
</tr>
<tr>
<td>FormService</td>
<td>表单Service，用于读取和任务、流程相关的表单数据</td>
</tr>
<tr>
<td>HistoryService</td>
<td>历史Service，可查询所有历史数据</td>
</tr>
<tr>
<td>ManagementService</td>
<td>引擎管理Service，和具体业务无关，可用查询引擎配置、数据库、作业等</td>
</tr>
</tbody></table>
<p>3、流程设计器：Activiti团队设计了基于BPMN2.0规范的设计器-Eclipse Designer，除此还有Signavio公司为Activiti定制的基于<strong>Web的Activiti Modeler流程设计器</strong>。</p>
<p>4、原生支持Spring：当前企业开发，基本上都会基于Spring去开发自己的系统，由于A  ctiviti原生支持Spring，所以很轻松地进行Spring集成。</p>
<p>5、分离运行时与历史数据：运行与历史数据的分离，可以加快运行时数据的性能，当需要历史数据时，我们在去查询。</p>
<h2 id="9-3-Activiti-应用"><a href="#9-3-Activiti-应用" class="headerlink" title="9.3 Activiti 应用"></a>9.3 Activiti 应用</h2><p>1、在系统集成方面：与ESB整合 / 与规则引擎整合 / 嵌入已有系统平台(也是本项目的需求)</p>
<p>2、在其他产品中应用：Alfresco公司的ECM产品在企业中应用，主要涉及文档管理 / 协作 / 记录管理 / 知识库管理 / Web内容管理等。</p>
<h2 id="9-4-Activiti框架与组件"><a href="#9-4-Activiti框架与组件" class="headerlink" title="9.4 Activiti框架与组件"></a>9.4 Activiti框架与组件</h2><p>Activiti最重要的就是<strong>引擎</strong>，除此之外就是外部的工具和组件。</p>
<table>
<thead>
<tr>
<th>Modeling</th>
<th>Runtion</th>
<th>Management</th>
</tr>
</thead>
<tbody><tr>
<td>Activiti Modeler</td>
<td>Activiti Engine</td>
<td>Activiti Exproler</td>
</tr>
<tr>
<td>Activiti Designer</td>
<td>Activiti REST</td>
<td></td>
</tr>
<tr>
<td>Activiti Kickstart</td>
<td></td>
<td></td>
</tr>
</tbody></table>
<p>下面对以上组件进行简单的说明：</p>
<p>1、<strong>Activiti Engine</strong>：最核心的模块，提供针对BPMN2.0规范的解析 / 执行 / 创建 / 管理(任务-流程实例) / 查询历史记录并生成相应报表等。</p>
<p>2、<strong>Activiti Modeler</strong>：模型设计器，非Activiti公司开发。用于将需求转换为规范流程定义。</p>
<p>3、<strong>Activiti Designer</strong>：设计器，与Activiti Modeler功能类似。</p>
<p>4、<strong>Activiti Exproler</strong>：用来管理仓库 / 用户 / 组，启动流程 / 任务办理等。</p>
<p>5、<strong>Activiti REST</strong>：提供REST风格的服务，允许客户端以JSON的方式与引擎的REST API交互，协议具有跨平台 / 跨语言。</p>
<h2 id="9-6-Activity-工作流要点"><a href="#9-6-Activity-工作流要点" class="headerlink" title="9.6 Activity 工作流要点"></a>9.6 Activity 工作流要点</h2><h3 id="9-6-1-Idea插件（学习）"><a href="#9-6-1-Idea插件（学习）" class="headerlink" title="9.6.1 Idea插件（学习）"></a>9.6.1 Idea插件（学习）</h3><p>IDEA插件用于Activity 画流程图使用，在2023 年IDEA中这个项目叫做 <code>Activiti BPMN visualizer</code>。可以直接在”Plugins”当中查到。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230204095247.png" alt="idea 插件"></p>
<p>使用IDEA插件的好处是在入门Demo的时候可以不依赖开源流程设计器组件即可绘制一些简单流程，并且由于遵循bpmn2的规范，可以通用在大部分工作流引擎上。</p>
<h3 id="9-6-2-常用-Service"><a href="#9-6-2-常用-Service" class="headerlink" title="9.6.2 常用 Service"></a>9.6.2 常用 Service</h3><p><strong>Activiti</strong> 提供了几个 <strong>Service</strong> 类，用来管理工作流，常用的有以下四项：</p>
<p><strong>1）</strong> RepositoryService：提供<strong>流程定义和部署</strong>等功能。比如说，实现流程的的部署、删除，暂停和激活以及流程的查询等功能</p>
<p><strong>2）</strong> RuntimeService：提供了处理<strong>流程实例</strong>不同步骤的结构和行为。包括启动流程实例、暂停和激活流程实例等功能</p>
<p><strong>3）</strong> TaskService：提供有关<strong>任务相关功能</strong>的服务。包括任务的查询、删除以及完成等功能</p>
<p><strong>4）</strong> HistoryService：提供 Activiti 引擎收集的<strong>历史记录信息</strong>服务。主要用于历史信息的查询功能</p>
<p>还有以下两项：</p>
<p>1）<strong>ManagementService</strong>：job 任务查询和数据库操作</p>
<p>2）<strong>DynamicBpmnService</strong>：无需重新部署就能修改流程定义内容</p>
<p>而 <strong>Spring Boot</strong> 集成 <strong>Activiti</strong> 实现工作流功能，也主要是采用这些 <strong>Service</strong> 所提供的 相应的 <strong>API</strong> 来实现的。</p>
<h3 id="9-6-3-ProcessEngine对象"><a href="#9-6-3-ProcessEngine对象" class="headerlink" title="9.6.3 ProcessEngine对象"></a>9.6.3 ProcessEngine对象</h3><p>ProcessEngine是Activity的工作引擎也是核心内容，作用是负责生成流程运行时的各种实例及数据、监控和管理流程的运行。实际使用过程一般会静态全局实例化这个对象，如果是Spring框架集成依赖则会由Spring帮我们完成对象创建和托管。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"> ProcessEngine processEngine =ProcessEngines.getDefaultProcessEngine();</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();  </span><br><span class="line">engine.getTaskService()  </span><br><span class="line">        .complete(<span class="string">"7502"</span>);</span><br></pre></td></tr></table></figure>



<h3 id="9-6-4-安全管理"><a href="#9-6-4-安全管理" class="headerlink" title="9.6.4 安全管理"></a>9.6.4 安全管理</h3><p>前面介绍过 Activity 工作流 和 Spring Security 是可以进行绑定和兼容的，并且我们使用的项目不想要Security 也可以通过注解的方式禁用，比如实际项目中就通过下面的方式禁用Spring 的 SecurityAutoConfiguration 和Activity 的 SecurityAutoConfiguration：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@SpringBootApplication</span>(exclude = &#123;DataSourceAutoConfiguration<span class="class">.<span class="keyword">class</span>,  </span></span><br><span class="line"><span class="class">        <span class="title">org</span>.<span class="title">activiti</span>.<span class="title">spring</span>.<span class="title">boot</span>.<span class="title">SecurityAutoConfiguration</span>.<span class="title">class</span>,  </span></span><br><span class="line"><span class="class">        <span class="title">org</span>.<span class="title">springframework</span>.<span class="title">boot</span>.<span class="title">autoconfigure</span>.<span class="title">security</span>.<span class="title">servlet</span>.<span class="title">SecurityAutoConfiguration</span>.<span class="title">class</span>  </span></span><br><span class="line"><span class="class">&#125;)</span></span><br></pre></td></tr></table></figure>



<h3 id="9-6-5-配置文件-activiti-cfg-xml"><a href="#9-6-5-配置文件-activiti-cfg-xml" class="headerlink" title="9.6.5 配置文件 activiti.cfg.xml"></a>9.6.5 配置文件 activiti.cfg.xml</h3><p>Activity 所需的配置文件也是Activiti核心配置文件，配置内容和我们平常配置JDBC连接类似。下面是参考的配置内容：</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span>  </span><br><span class="line"><span class="tag">&lt;<span class="name">beans</span> <span class="attr">xmlns</span>=<span class="string">"http://www.springframework.org/schema/beans"</span>  </span></span><br><span class="line"><span class="tag">       <span class="attr">xmlns:xsi</span>=<span class="string">"http://www.w3.org/2001/XMLSchema-instance"</span>  </span></span><br><span class="line"><span class="tag">       <span class="attr">xsi:schemaLocation</span>=<span class="string">"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"</span>&gt;</span>  </span><br><span class="line">  </span><br><span class="line">    <span class="tag">&lt;<span class="name">bean</span> <span class="attr">id</span>=<span class="string">"processEngineConfiguration"</span> <span class="attr">class</span>=<span class="string">"org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"</span>&gt;</span>  </span><br><span class="line"><span class="comment">&lt;!--        配置数据库相关--&gt;</span>  </span><br><span class="line"><span class="comment">&lt;!--        数据库驱动--&gt;</span>  </span><br><span class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"jdbcDriver"</span> <span class="attr">value</span>=<span class="string">"com.mysql.cj.jdbc.Driver"</span>&gt;</span><span class="tag">&lt;/<span class="name">property</span>&gt;</span>  </span><br><span class="line"><span class="comment">&lt;!--        数据库链接--&gt;</span>  </span><br><span class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"jdbcUrl"</span> <span class="attr">value</span>=<span class="string">"jdbc:mysql://localhost:12306/test?useSSL=false<span class="symbol">&amp;amp;</span> useUnicode=true<span class="symbol">&amp;amp;</span> characterEncoding=utf8<span class="symbol">&amp;amp;</span> serverTimezone=Asia/Shanghai<span class="symbol">&amp;amp;</span> nullCatalogMeansCurrent=true"</span>&gt;</span><span class="tag">&lt;/<span class="name">property</span>&gt;</span>  </span><br><span class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"jdbcUsername"</span> <span class="attr">value</span>=<span class="string">"xxxxx"</span>&gt;</span><span class="tag">&lt;/<span class="name">property</span>&gt;</span>  </span><br><span class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"jdbcPassword"</span> <span class="attr">value</span>=<span class="string">"xxxxx"</span>&gt;</span><span class="tag">&lt;/<span class="name">property</span>&gt;</span>  </span><br><span class="line"><span class="comment">&lt;!--        数据库表在生成时的依赖--&gt;</span>  </span><br><span class="line">        <span class="tag">&lt;<span class="name">property</span> <span class="attr">name</span>=<span class="string">"databaseSchemaUpdate"</span> <span class="attr">value</span>=<span class="string">"true"</span>&gt;</span><span class="tag">&lt;/<span class="name">property</span>&gt;</span>  </span><br><span class="line">    <span class="tag">&lt;/<span class="name">bean</span>&gt;</span>  </span><br><span class="line">  </span><br><span class="line"><span class="tag">&lt;/<span class="name">beans</span>&gt;</span></span><br></pre></td></tr></table></figure>



<h3 id="9-6-6-application-yml-配置文件"><a href="#9-6-6-application-yml-配置文件" class="headerlink" title="9.6.6 application.yml 配置文件"></a>9.6.6 application.yml 配置文件</h3><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">datasource:</span></span><br><span class="line">    <span class="string">url:</span> <span class="string">jdbc:mysql://localhost:12306/test?useUnicode=true&amp;characterEncoding=utf8&amp;nullCatalogMeansCurrent=true</span></span><br><span class="line">    <span class="string">username:</span> <span class="string">xxx</span></span><br><span class="line">    <span class="string">password:</span> <span class="string">xxx</span></span><br><span class="line">    <span class="string">driver-class-name:</span> <span class="string">com.mysql.cj.jdbc.Driver</span></span><br><span class="line">  <span class="attr">activiti:</span></span><br><span class="line"><span class="comment">#    flase：       默认值。activiti在启动时，会对比数据库表中保存的版本，如果没有表或者版本不匹配，将抛出异常。（生产环境常用）</span></span><br><span class="line"><span class="comment">#    true：        activiti会对数据库中所有表进行更新操作。如果表不存在，则自动创建。（开发时常用）</span></span><br><span class="line"><span class="comment">#    create_drop： 在activiti启动时创建表，在关闭时删除表（必须手动关闭引擎，才能删除表）。（单元测试常用）</span></span><br><span class="line"><span class="comment">#    drop-create： 在activiti启动时删除原来的旧表，然后在创建新表（不需要手动关闭引擎）。</span></span><br><span class="line">    <span class="string">database-schema-update:</span> <span class="literal">true</span></span><br><span class="line">    <span class="comment">#默认不生成历史表，这里开启</span></span><br><span class="line">    <span class="string">db-history-used:</span> <span class="literal">true</span></span><br><span class="line">    <span class="comment">#历史登记</span></span><br><span class="line"><span class="comment">#    none: 不记录历史流程，性能高，流程结束后不可读取</span></span><br><span class="line"><span class="comment">#    Activity: 归档流程实例和活动实例，流程变量不同步</span></span><br><span class="line"><span class="comment">#    audit: 默认值，在activiti基础上同步变量值，保存表单属性</span></span><br><span class="line"><span class="comment">#    full: 性能较差，记录所有实例和变量细节变化，最完整的历史记录，如果需要日后跟踪详细可以开启full（一般不建议开启）</span></span><br><span class="line">    <span class="string">history-level:</span> <span class="string">full</span></span><br><span class="line">    <span class="string">deployment-mode:</span>  <span class="string">never-fail</span> <span class="comment"># 关闭 SpringAutoDeployment</span></span><br></pre></td></tr></table></figure>

<ul>
<li><p>database-schema-update 配置为 <strong>true</strong>，即每次项目启动，都会对数据库进行更新操作，如果表不存在，则自动创建</p>
</li>
<li><p>db-history-used 配置为 <strong>true</strong> 由于默认是不生成历史表的，配置为 <strong>true</strong>表示需要生成。</p>
</li>
<li><p>history-level 配置 为 <strong>full</strong>，表示记录最完整的历史记录。</p>
</li>
<li><p>deployment-mode 配置为 <strong>never-fail</strong> ，即关闭掉 <strong>SpringAutoDeployment</strong>。如果不关闭，每次重新启动项目的时候，总是会在 <strong>ACT_RE_DEPLOYMENT</strong> 自动创建一个名为 <strong>SpringAutoDeployment</strong> 工作流记录。</p>
<ul>
<li>影响：在开发阶段，需要经常重启项目，久而久之就会导致 <strong>ACT_RE_DEPLOYMENT</strong> 的记录越来越大了</li>
</ul>
</li>
</ul>
<h2 id="9-7-表结构"><a href="#9-7-表结构" class="headerlink" title="9.7 表结构"></a>9.7 表结构</h2><p>如果配置了开启历史表的使用开关<strong>db-history-used: true</strong>。那么这里会额外创建历史表结构。项目启动之后会发现项目数据的会自动增加了 <strong>28</strong> 张 <strong>ACT</strong> 开头的表。</p>
<h3 id="9-7-1-5-种数据库表"><a href="#9-7-1-5-种数据库表" class="headerlink" title="9.7.1 5 种数据库表"></a>9.7.1 5 种数据库表</h3><p>迁移Activity 需要导入所需的数据库表，这些表的特点是所有的表都以<strong>ACT_</strong> 开头，第二部分表示对应的标识。</p>
<p>比如：</p>
<p>act_hi_*：’hi’表示 history，此前缀的表包含历史数据，如历史(结束)流程实例，变量，任务等等。</p>
<p>act_ge_*：’ge’表示 general，此前缀的表为通用数据，用于不同场景中。</p>
<p>act_evt_*：’evt’表示 event，此前缀的表为事件日志。</p>
<p>act_procdef_*：’procdef’表示 processdefine，此前缀的表为记录流程定义信息。</p>
<p>act_re_*：’re’表示 repository，此前缀的表包含了流程定义和流程静态资源(图片，规则等等)。</p>
<p>act_ru_*：’ru’表示 runtime，此前缀的表是记录运行时的数据，包含流程实例，任务，变量，异步任务等运行中的数据。Activiti只在流程实例执行过程中保存这些数据，在流程结束时就会删除这些记录。</p>
<h3 id="9-7-2-所有数据表简介"><a href="#9-7-2-所有数据表简介" class="headerlink" title="9.7.2 所有数据表简介"></a>9.7.2 所有数据表简介</h3><table>
<thead>
<tr>
<th>表名</th>
<th>表注释</th>
</tr>
</thead>
<tbody><tr>
<td>act_ge_bytearray</td>
<td>二进制数据表，存储通用的流程定义和流程资源。</td>
</tr>
<tr>
<td>act_ge_property</td>
<td>系统相关属性，属性数据表存储整个流程引擎级别的数据，初始化表结构时，会默认插入三条记录。</td>
</tr>
<tr>
<td>act_re_deployment</td>
<td>部署信息表</td>
</tr>
<tr>
<td>act_re_model</td>
<td>流程设计模型部署表</td>
</tr>
<tr>
<td>act_re_procdef</td>
<td>流程定义数据表</td>
</tr>
<tr>
<td>act_ru_deadletter_job</td>
<td>作业死亡信息表，作业失败超过重试次数</td>
</tr>
<tr>
<td>act_ru_event_subscr</td>
<td>运行时事件表</td>
</tr>
<tr>
<td>act_ru_execution</td>
<td>运行时流程执行实例表</td>
</tr>
<tr>
<td>act_ru_identitylink</td>
<td>运行时用户信息表</td>
</tr>
<tr>
<td>act_ru_integration</td>
<td>运行时积分表</td>
</tr>
<tr>
<td>act_ru_job</td>
<td>运行时作业信息表</td>
</tr>
<tr>
<td>act_ru_suspended_job</td>
<td>运行时作业暂停表</td>
</tr>
<tr>
<td>act_ru_task</td>
<td>运行时任务信息表</td>
</tr>
<tr>
<td>act_ru_timer_job</td>
<td>运行时定时器作业表</td>
</tr>
<tr>
<td>act_ru_variable</td>
<td>运行时变量信息表</td>
</tr>
<tr>
<td>act_hi_actinst</td>
<td>历史节点表</td>
</tr>
<tr>
<td>act_hi_attachment</td>
<td>历史附件表</td>
</tr>
<tr>
<td>act_hi_comment</td>
<td>历史意见表</td>
</tr>
<tr>
<td>act_hi_detail</td>
<td>历史详情表，提供历史变量的查询</td>
</tr>
<tr>
<td>act_hi_identitylink</td>
<td>历史流程用户信息表</td>
</tr>
<tr>
<td>act_hi_procinst</td>
<td>历史流程实例表</td>
</tr>
<tr>
<td>act_hi_taskinst</td>
<td>历史任务实例表</td>
</tr>
<tr>
<td>act_hi_varinst</td>
<td>历史变量表</td>
</tr>
<tr>
<td>act_evt_log</td>
<td>流程引擎的通用事件日志记录表</td>
</tr>
<tr>
<td>act_procdef_info</td>
<td>流程定义的动态变更信息</td>
</tr>
</tbody></table>
<p>这里再分类了解一下：</p>
<h4 id="全局通用数据（ACT-GE-）"><a href="#全局通用数据（ACT-GE-）" class="headerlink" title="全局通用数据（ACT_GE_*）"></a>全局通用数据（ACT_GE_*）</h4><table>
<thead>
<tr>
<th>表名</th>
<th>解释</th>
</tr>
</thead>
<tbody><tr>
<td>ACT_GE_BYTEARRAY</td>
<td>二进制数据表，存储通用的流程定义和流程资源。</td>
</tr>
<tr>
<td>ACT_GE_PROPERTY</td>
<td>系统相关属性，属性数据表存储整个流程引擎级别的数据。</td>
</tr>
</tbody></table>
<h4 id="静态信息表（ACT-RE-）"><a href="#静态信息表（ACT-RE-）" class="headerlink" title="静态信息表（ACT_RE_*）"></a>静态信息表（ACT_RE_*）</h4><table>
<thead>
<tr>
<th>表名</th>
<th>解释</th>
</tr>
</thead>
<tbody><tr>
<td>ACT_RE_DEPLOYMENT</td>
<td>部署信息表</td>
</tr>
<tr>
<td>ACT_RE_MODEL</td>
<td>流程设计模型部署表</td>
</tr>
<tr>
<td>ACT_RE_PROCDEF</td>
<td>流程定义数据表</td>
</tr>
</tbody></table>
<h4 id="运行数据（ACT-RU-）"><a href="#运行数据（ACT-RU-）" class="headerlink" title="运行数据（ACT_RU_*）"></a>运行数据（ACT_RU_*）</h4><table>
<thead>
<tr>
<th>表名</th>
<th>解释</th>
</tr>
</thead>
<tbody><tr>
<td>ACT_RU_DEADLETTER_JOB</td>
<td>无法执行工作表： 如果一个任务执行了很多次，都无法执行，那么这个任务会写到此表</td>
</tr>
<tr>
<td>ACT_RU_EVENT_SUBSCR</td>
<td>运行时事件 throwEvent、catchEvent 时间监听信息表</td>
</tr>
<tr>
<td>ACT_RU_EXECUTION</td>
<td>运行时流程执行实例</td>
</tr>
<tr>
<td>ACT_RU_IDENTITYLINK</td>
<td>运行时流程人员表，主要存储任务节点与参与者的相关信息</td>
</tr>
<tr>
<td>ACT_RU_INTEGRATION</td>
<td>运行时积分表</td>
</tr>
<tr>
<td>ACT_RU_JOB</td>
<td>运行时定时任务数据表</td>
</tr>
<tr>
<td>ACT_RU_SUSPENDED_JOB</td>
<td>暂停的工作，流程中有一个定时任务，如果把这个任务停止工作了，这个任务会在act_ru_suspended_job中写入数据</td>
</tr>
<tr>
<td>ACT_RU_TASK</td>
<td>运行时任务节点表</td>
</tr>
<tr>
<td>ACT_RU_TIMER_JOB</td>
<td>运行时定时器作业表</td>
</tr>
<tr>
<td>ACT_RU_VARIABLE</td>
<td>运行时流程变量数据表</td>
</tr>
</tbody></table>
<h4 id="历史数据（ACT-HI-）"><a href="#历史数据（ACT-HI-）" class="headerlink" title="历史数据（ACT_HI_*）"></a>历史数据（ACT_HI_*）</h4><table>
<thead>
<tr>
<th>表名</th>
<th>表注释</th>
</tr>
</thead>
<tbody><tr>
<td>act_hi_actinst</td>
<td>历史节点表</td>
</tr>
<tr>
<td>act_hi_attachment</td>
<td>历史附件表</td>
</tr>
<tr>
<td>act_hi_comment</td>
<td>历史意见表</td>
</tr>
<tr>
<td>act_hi_detail</td>
<td>历史详情表，提供历史变量的查询</td>
</tr>
<tr>
<td>act_hi_identitylink</td>
<td>历史流程用户信息表</td>
</tr>
<tr>
<td>act_hi_procinst</td>
<td>历史流程实例表</td>
</tr>
<tr>
<td>act_hi_taskinst</td>
<td>历史任务实例表</td>
</tr>
<tr>
<td>act_hi_varinst</td>
<td>历史变量表</td>
</tr>
</tbody></table>
<h4 id="其它表"><a href="#其它表" class="headerlink" title="其它表"></a>其它表</h4><table>
<thead>
<tr>
<th>表名</th>
<th>解释</th>
</tr>
</thead>
<tbody><tr>
<td>ACT_EVT_LOG</td>
<td>事件日志</td>
</tr>
<tr>
<td>ACT_PROCDEF_INFO</td>
<td>流程定义的动态变更信息</td>
</tr>
</tbody></table>
<p>简单了解Activity的结构之后，下面介绍项目如何集成 Activity。</p>
<h1 id="十、项目集成-Activity"><a href="#十、项目集成-Activity" class="headerlink" title="十、项目集成 Activity"></a>十、项目集成 Activity</h1><p>万事开头难，集成Activity到项目可能是整个学习过程最难的一步，下文会将个人集成过程中遇到的问题一并罗列。</p>
<h3 id="10-1-版本选择"><a href="#10-1-版本选择" class="headerlink" title="10.1 版本选择"></a>10.1 版本选择</h3><p>可以参考网络资料选择合适的版本。实际工作中由于可参考案例权衡、时间原因和经验不足等种种原因，个人没有选择资料和成功案例比较少的 Activity7 的版本，而是使用了网上可供参考资料比较多的 6 的版本。</p>
<p>如果要集成Activity 7，可以使用下面的依赖。</p>
<blockquote>
<p>根据网络反馈和个人实际尝试，发现集成 Activity 7 同样会因为自带依赖版本冲突导致各种问题。</p>
</blockquote>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.activiti<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>activiti-spring-boot-starter<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>7.1.0.M6<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>实际学习过程个人选择了下面的依赖 <s>选择低版本的根本原因是网上有的代码抄</s>：</p>
<ol>
<li>Activity的相关组件依赖，比如将JSON数据转化为Activity的模型的编码依赖，bpmn文件转为数据库以及逆向转化依赖，还有前前端WEB组件需要的一部分依赖。</li>
</ol>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- Activity 依赖 --&gt;</span>  </span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.activiti<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>activiti-json-converter<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">version</span>&gt;</span>6.0.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span>  </span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span>  </span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.activiti<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>activiti-bpmn-layout<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">version</span>&gt;</span>6.0.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span>  </span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span>  </span><br><span class="line">  </span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.xmlgraphics<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>batik-transcoder<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">version</span>&gt;</span>1.10<span class="tag">&lt;/<span class="name">version</span>&gt;</span>  </span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.xmlgraphics<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>batik-codec<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">version</span>&gt;</span>1.9<span class="tag">&lt;/<span class="name">version</span>&gt;</span>  </span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<ol start="2">
<li>引入Activity依赖，注意Activity6 使用的是还是ORM的查询方式，自带的mybatis依赖可能和SpringBoot不兼容，所以需要排除依赖附带的低版本Mybatis依赖。</li>
</ol>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.activiti<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>activiti-spring-boot-starter-basic<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">version</span>&gt;</span>6.0.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">exclusions</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">exclusion</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.mybatis<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">				<span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>mybatis<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;/<span class="name">exclusion</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;/<span class="name">exclusions</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>添加以上依赖之后，启动项目检查是否可以正常启动。</p>
<h2 id="10-2-集成-Activity-web-编辑器"><a href="#10-2-集成-Activity-web-编辑器" class="headerlink" title="10.2 集成 Activity web 编辑器"></a>10.2 集成 Activity web 编辑器</h2><p>由于实际工作需求中要把Activity的 Web 版本组件（Activiti Explorer）集成到项目当中，时间紧迫关系，个人选择参考网上资料最终选择从成熟的项目中拷贝前端依赖学习。</p>
<p>Activity 6.0 之后默认不再集成任何 Expolorer 的组件内容，但是可以从 Activity 5 当中找到相关依赖。参考链接：</p>
<ul>
<li><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3BjaGFyb2VuL2FjdGl2aXRpLXdlYi9ibG9iL21hc3Rlci93YXJzL2FjdGl2aXRpLWV4cGxvcmVyLndhcg==" title="https://github.com/pcharoen/activiti-web/blob/master/wars/activiti-explorer.war">https://github.com/pcharoen/activiti-web/blob/master/wars/activiti-explorer.war<i class="fa fa-external-link"></i></span></li>
</ul>
<p>从官方的war包中进行集成比较麻烦，更为快捷的方式是利用网络开源项目直接拷贝前端依赖，兼容到其他项目会稍微好一些。</p>
<ul>
<li><span class="exturl" data-url="aHR0cHM6Ly9naXRlZS5jb20vc2hlbnpoYW53YW5nL1J1b1lpLWFjdGl2aXRp" title="https://gitee.com/shenzhanwang/RuoYi-activiti">RuoYi-activiti: 打造最好用的OA数字化解决方案，基于Activiti6.0，集流程设计、流程部署、流程执行、任务办理、流程监控于一体的开源工作流开发平台。 (gitee.com)<i class="fa fa-external-link"></i></span></li>
</ul>
<p>如果觉得成熟项目代码看起来比较复杂难以搜索，可以参考下面这个项目，它基于SpringBoot实现非常简单易懂：</p>
<p><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2p1emhpemhhbmcvc3ByaW5nYm9vdDItYWN0aXZpdGktZGVzaWdu" title="https://github.com/juzhizhang/springboot2-activiti-design">https://github.com/juzhizhang/springboot2-activiti-design<i class="fa fa-external-link"></i></span></p>
<p>以<strong>Ruoyi</strong>的项目为例，我们需要拷贝下面的内容：</p>
<ul>
<li>src / main / resources / static / diagram-viewer（建议放到 static 目录）</li>
<li>src / main / resources / static / editor-app（建议放到 static 目录）</li>
<li>src / main / resources / templates / modeler.html （建议放到 templates 目录下）</li>
<li>stencilset.json 文件（放到 resources 下）</li>
</ul>
<blockquote>
<p>注意这个组件使用的前端框架为国外比较热门的 angular，比较少见。</p>
</blockquote>
<p>注意拷贝完成只是集成第一步，这时候前端是无法正常使用，我们还需要定义控制器，并且给前端提供必要API的接口。</p>
<h2 id="10-3-提供Activity-web-编辑器必要API接口"><a href="#10-3-提供Activity-web-编辑器必要API接口" class="headerlink" title="10.3  提供Activity web 编辑器必要API接口"></a>10.3  提供Activity web 编辑器必要API接口</h2><p>要正常使用 Activity web 编辑器，项目中必须要提供几个必要的API接口。</p>
<h3 id="10-3-1-editor-跳转集成"><a href="#10-3-1-editor-跳转集成" class="headerlink" title="10.3.1 editor 跳转集成"></a>10.3.1 editor 跳转集成</h3><p>为了能够进入到编辑流程模型的页面，首先需要提供一个接口跳转到对应html文件。html 文件对应 modeler.html。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@GetMapping</span>(<span class="string">"/editor"</span>)  </span><br><span class="line"><span class="function"><span class="keyword">public</span> String <span class="title">editor</span><span class="params">()</span></span>&#123;  </span><br><span class="line">    <span class="keyword">return</span> <span class="string">"Activity/modeler"</span>;  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>当我们打开WEB编辑器进行流程模型编辑页面（modeler.html），我们有可能会看到白板，这是因为页面还缺少数据。简单来说就是内部需要<strong>结合上下文</strong>获取模型资源和组件JSON资源。</p>
<blockquote>
<p>接口请求URL请求格式可以通过改前端脚本或者直接修改源码的方式调整。</p>
</blockquote>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230210150746.png" alt="activity web json"></p>
<p>上面主要包含了后缀分别是<code>sterncliset</code>和<code>json</code>的接口。</p>
<h3 id="10-3-2-sterncliset-接口提供"><a href="#10-3-2-sterncliset-接口提供" class="headerlink" title="10.3.2 sterncliset 接口提供"></a>10.3.2 sterncliset 接口提供</h3><p><code>stencilset.json</code>的大致内容如下，根据英文单词描述，很容易猜测出负责管理前端的组件展示。</p>
<blockquote>
<p>案例：<code>activiti-explorer/editor/stencilset?version=1676012813897</code>。</p>
</blockquote>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230423153805.png" alt="stemcliset"></p>
<p>提供<code>/editor/stencilset</code>控制层接口，通过service层调用获取 json文件内容。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@RequestMapping</span>(value = <span class="string">"/editor/stencilset"</span>, method = RequestMethod.GET, produces = <span class="string">"application/json;charset=utf-8"</span>)  </span><br><span class="line"><span class="meta">@ResponseBody</span>  </span><br><span class="line"><span class="function"><span class="keyword">public</span> String <span class="title">getStencilset</span><span class="params">()</span> </span>&#123;  </span><br><span class="line">    <span class="keyword">try</span> &#123;  </span><br><span class="line">        <span class="keyword">return</span> ActivityModelService.getStencilset(STENCIL_SET);  </span><br><span class="line">    &#125; <span class="keyword">catch</span> (Exception e) &#123;  </span><br><span class="line">        log.error(<span class="string">"Error while loading stencil set"</span>, e);  </span><br><span class="line">        <span class="keyword">return</span> <span class="string">""</span>;  </span><br><span class="line">    &#125;  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>service中利用了Class类加载器机制，因为 json 文件是放到 <code>resources</code>下面的，可以直接从“根路径” 获取到文件。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> String <span class="title">getStencilset</span><span class="params">(String resource)</span> </span>&#123;  </span><br><span class="line">    InputStream stencilsetStream = <span class="keyword">this</span>.getClass().getClassLoader().getResourceAsStream(resource);  </span><br><span class="line">    <span class="keyword">try</span> &#123;  </span><br><span class="line">        <span class="keyword">return</span> IOUtils.toString(stencilsetStream, <span class="string">"utf-8"</span>);  </span><br><span class="line">    &#125; <span class="keyword">catch</span> (Exception e) &#123;  </span><br><span class="line">        <span class="keyword">throw</span> <span class="keyword">new</span> ActivitiException(<span class="string">"Error while loading stencil set"</span>, e);  </span><br><span class="line">    &#125;  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="10-3-3-加载指定模型数据"><a href="#10-3-3-加载指定模型数据" class="headerlink" title="10.3.3 加载指定模型数据"></a>10.3.3 加载指定模型数据</h3><p><code>json</code> 接口需要对应下面的控制器。</p>
<blockquote>
<p>repositoryService：流程仓库Service，用于管理流程仓库，如：部署、删除、读取流程资源。</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="meta">@RequestMapping</span>(value=<span class="string">"/model/&#123;modelId&#125;/json"</span>, method = RequestMethod.GET, produces = <span class="string">"application/json"</span>)  </span><br><span class="line"><span class="function"><span class="keyword">public</span> ObjectNode <span class="title">getEditorJson</span><span class="params">(@PathVariable String modelId)</span> </span>&#123;  </span><br><span class="line">    ObjectNode modelNode = <span class="keyword">null</span>;  </span><br><span class="line">  </span><br><span class="line">    Model model = repositoryService.getModel(modelId);  </span><br><span class="line">  </span><br><span class="line">    <span class="keyword">if</span> (model != <span class="keyword">null</span>) &#123;  </span><br><span class="line">        <span class="keyword">try</span> &#123;  </span><br><span class="line">            <span class="keyword">if</span> (StringUtils.isNotEmpty(model.getMetaInfo())) &#123;  </span><br><span class="line">                modelNode = (ObjectNode) objectMapper.readTree(model.getMetaInfo());  </span><br><span class="line">            &#125; <span class="keyword">else</span> &#123;  </span><br><span class="line">                modelNode = objectMapper.createObjectNode();  </span><br><span class="line">                modelNode.put(ModelDataJsonConstants.MODEL_NAME, model.getName());  </span><br><span class="line">            &#125;  </span><br><span class="line">            modelNode.put(ModelDataJsonConstants.MODEL_ID, model.getId());  </span><br><span class="line">            ObjectNode editorJsonNode = (ObjectNode) objectMapper.readTree(  </span><br><span class="line">                    <span class="keyword">new</span> String(repositoryService.getModelEditorSource(model.getId()), <span class="string">"utf-8"</span>));  </span><br><span class="line">            modelNode.put(<span class="string">"model"</span>, editorJsonNode);  </span><br><span class="line">  </span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e) &#123;  </span><br><span class="line">            LOGGER.error(<span class="string">"Error creating model JSON"</span>, e);  </span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> ActivitiException(<span class="string">"Error creating model JSON"</span>, e);  </span><br><span class="line">        &#125;  </span><br><span class="line">    &#125;  </span><br><span class="line">    <span class="keyword">return</span> modelNode;  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


<h3 id="10-3-4-保存模型接口"><a href="#10-3-4-保存模型接口" class="headerlink" title="10.3.4 保存模型接口"></a>10.3.4 保存模型接口</h3><p>模型绘制完成之后，我们需要保存数据接口，下面接口对应保存模型的操作。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@RequestMapping</span>(value = <span class="string">"/model/&#123;modelId&#125;/save"</span>, method = RequestMethod.PUT)  </span><br><span class="line"><span class="meta">@ResponseStatus</span>(value = HttpStatus.OK)  </span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">saveModel</span><span class="params">(@PathVariable String modelId,  </span></span></span><br><span class="line"><span class="function"><span class="params">                      String name,  </span></span></span><br><span class="line"><span class="function"><span class="params">                      String description,  </span></span></span><br><span class="line"><span class="function"><span class="params">                      String json_xml,  </span></span></span><br><span class="line"><span class="function"><span class="params">                      String svg_xml)</span> </span>&#123;  </span><br><span class="line">    <span class="keyword">try</span> &#123;  </span><br><span class="line">        ActivityModelService.saveModel(modelId, name, description, json_xml, svg_xml);  </span><br><span class="line">    &#125;<span class="keyword">catch</span> (Exception e)&#123;  </span><br><span class="line">        log.error(<span class="string">"has error "</span>, e);  </span><br><span class="line">    &#125;  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>saveModel方法代码如下：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span>  </span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">saveModel</span><span class="params">(String modelId, String name, String description, String jsonXmlBytes, String svgXmlBytes)</span> </span>&#123;  </span><br><span class="line">    <span class="keyword">try</span> &#123;  </span><br><span class="line">        Model model = repositoryService.getModel(modelId);  </span><br><span class="line">        ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo());  </span><br><span class="line">        modelJson.put(ModelDataJsonConstants.MODEL_NAME, name);  </span><br><span class="line">        modelJson.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description);  </span><br><span class="line">        model.setMetaInfo(modelJson.toString());  </span><br><span class="line">        model.setName(name);  </span><br><span class="line">        model.setDeploymentId(<span class="keyword">null</span>);  </span><br><span class="line">        Integer version = model.getVersion();  </span><br><span class="line">        version++;  </span><br><span class="line">        model.setVersion(version);  </span><br><span class="line">        repositoryService.saveModel(model);  </span><br><span class="line">        repositoryService.addModelEditorSource(model.getId(), jsonXmlBytes.getBytes(StandardCharsets.UTF_8));  </span><br><span class="line">        InputStream svgStream = <span class="keyword">new</span> ByteArrayInputStream(svgXmlBytes.getBytes(StandardCharsets.UTF_8));  </span><br><span class="line">        TranscoderInput input = <span class="keyword">new</span> TranscoderInput(svgStream);  </span><br><span class="line">        PNGTranscoder transcoder = <span class="keyword">new</span> PNGTranscoder();  </span><br><span class="line">        <span class="comment">// Setup output  </span></span><br><span class="line">        ByteArrayOutputStream outStream = <span class="keyword">new</span> ByteArrayOutputStream();  </span><br><span class="line">        TranscoderOutput output = <span class="keyword">new</span> TranscoderOutput(outStream);  </span><br><span class="line">        <span class="comment">// Do the transformation  </span></span><br><span class="line">        transcoder.transcode(input, output);  </span><br><span class="line">        <span class="keyword">final</span> <span class="keyword">byte</span>[] result = outStream.toByteArray();  </span><br><span class="line">        repositoryService.addModelEditorSourceExtra(model.getId(), result);  </span><br><span class="line">        outStream.close();  </span><br><span class="line">    &#125; <span class="keyword">catch</span> (Exception e) &#123;  </span><br><span class="line">        log.error(<span class="string">"Error saving model"</span>, e);  </span><br><span class="line">        <span class="keyword">throw</span> <span class="keyword">new</span> ActivitiException(<span class="string">"Error saving model"</span>, e);  </span><br><span class="line">    &#125;  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="10-3-5-关闭页面"><a href="#10-3-5-关闭页面" class="headerlink" title="10.3.5 关闭页面"></a>10.3.5 关闭页面</h3><p>根据实际项目情况，有可能需要调整点击关闭请求地址。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">closeEditor: <span class="function"><span class="keyword">function</span>(<span class="params">services</span>) </span>&#123;  </span><br><span class="line">   <span class="built_in">window</span>.location.href = <span class="string">'./'</span>;  </span><br><span class="line">&#125;,</span><br></pre></td></tr></table></figure>

<h3 id="10-3-6-去除Activity-logo"><a href="#10-3-6-去除Activity-logo" class="headerlink" title="10.3.6 去除Activity logo"></a>10.3.6 去除Activity logo</h3><p>搜索<code>.navbar-header</code>，并且修改为下面的内容。</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.navbar-header</span> &#123;  </span><br><span class="line">    <span class="attribute">padding-top</span>: <span class="number">0px</span>;  </span><br><span class="line">    <span class="attribute">line-height</span>: <span class="number">40px</span>;  </span><br><span class="line">    <span class="attribute">height</span>: <span class="number">40px</span>;  </span><br><span class="line">    <span class="attribute">color</span>: <span class="number">#FFFFFF</span>;  </span><br><span class="line">    <span class="comment">/*background: url(../images/logo.png) no-repeat 10px center;*/</span>  </span><br><span class="line">    <span class="comment">/*width: 180px;*/</span>    <span class="attribute">font-size</span>: <span class="number">20px</span>;  </span><br><span class="line">    <span class="attribute">margin-left</span>: <span class="number">30px</span>;  </span><br><span class="line">    <span class="attribute">font-weight</span>: <span class="number">660</span>;  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>在 <code>moderler.html</code>文件中，删除logo图片展示：</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424150457.png" alt="moderler"></p>
<h3 id="10-3-7-不必要组件流程组件"><a href="#10-3-7-不必要组件流程组件" class="headerlink" title="10.3.7 不必要组件流程组件"></a>10.3.7 不必要组件流程组件</h3><p>可以全局搜索下面的注释，或者搜索<code>stencil-controller.js</code>文件找到下面的内容。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// Add the stencil item to the correct group</span></span><br></pre></td></tr></table></figure>

<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230423164223.png" alt="不必要组件流程"></p>
<p>修改下面的代码，代码内部维护一个List，表示前端需要展示的内容，<code>currentGroup</code>用于过滤出符合的组件即可。</p>
<blockquote>
<p>这部分功能是要去掉不需要的功能按钮，减少误操作的可能性。</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 20230218 fixed  </span></span><br><span class="line"><span class="keyword">var</span> sideList = [<span class="string">'StartNoneEvent'</span>, <span class="string">'EndNoneEvent'</span>, <span class="string">'UserTask'</span>];  </span><br><span class="line">  </span><br><span class="line"><span class="comment">//  </span></span><br><span class="line"><span class="keyword">if</span> (currentGroup) &#123;  </span><br><span class="line"> <span class="comment">// Add the stencil item to the correct group  </span></span><br><span class="line"> currentGroup.items.push(stencilItem);  </span><br><span class="line"> <span class="keyword">if</span> (ignoreForPaletteDefinition.indexOf(stencilItem.id) &lt; <span class="number">0</span>) &#123;  </span><br><span class="line">     <span class="keyword">if</span>(sideList.include(stencilItem.id))&#123;  </span><br><span class="line">            <span class="built_in">console</span>.log(stencilItem);  </span><br><span class="line">            currentGroup.paletteItems.push(stencilItem);  </span><br><span class="line">  </span><br><span class="line">        &#125;  </span><br><span class="line"> &#125;  </span><br><span class="line">  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h3 id="10-3-8-隐藏不必要的底部编辑窗口"><a href="#10-3-8-隐藏不必要的底部编辑窗口" class="headerlink" title="10.3.8 隐藏不必要的底部编辑窗口"></a>10.3.8 隐藏不必要的底部编辑窗口</h3><p>底部编辑窗口也需要隐藏掉不需要的内容，隐藏思路和7点类似。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230423164546.png" alt="隐藏不必要窗口"></p>
<p>搜索<code>selectedItem.properties.push(currentProperty);</code>，或者找到文件<code>stencil-controller.js</code>找到下面的内容。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">selectedItem.properties.push(currentProperty);</span><br></pre></td></tr></table></figure>

<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230423164633.png" alt="隐藏不必要的底部编辑窗口"></p>
<p>依葫芦画瓢，这里也添加一个数组：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> includeProperty = [<span class="string">'oryx-process_id'</span>, <span class="string">'oryx-name'</span>, <span class="string">'oryx-documentation'</span>, <span class="string">'oryx-usertaskassignment'</span>];  </span><br><span class="line"><span class="keyword">if</span>(includeProperty.include(currentProperty.key))&#123;  </span><br><span class="line">    selectedItem.properties.push(currentProperty);  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>这时候你可能会好奇，这些啥 <code>stencilset.json</code>，实际上结合前端展示的数据标签以及<code>stencilset.json</code>可以找到相关内容，当然仔细阅读源代码也是种办法。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">'oryx-process_id'</span>, <span class="string">'oryx-name'</span>, <span class="string">'oryx-documentation'</span>, <span class="string">'oryx-usertaskassignment</span></span><br></pre></td></tr></table></figure>



<h3 id="10-3-9-分配负责人转为下拉框"><a href="#10-3-9-分配负责人转为下拉框" class="headerlink" title="10.3.9 分配负责人转为下拉框"></a>10.3.9 分配负责人转为下拉框</h3><p>实际应用中个人对于源码进行调整，把Assignee原本的流程变量表达式控制节点流转功能（下文会补充这个用法），转为选择固定的下拉系统角色，等于说是阉割灵活性使得非开发人员也可以正常上手（这部分完全是业务需要）。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424151054.png" alt="分配负责人转为下拉框"></p>
<p>实现这样的效果要查找到Activity这部分的源码，查找需要花不少时间这里就直接说答案了，找到<code>assignment-popup.html</code>文件，在开头第十行左右的位置。</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"row row-no-gutter"</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"form-group"</span>&gt;</span>  </span><br><span class="line">           <span class="tag">&lt;<span class="name">label</span> <span class="attr">for</span>=<span class="string">"assigneeField"</span>&gt;</span>&#123;&#123;'PROPERTY.ASSIGNMENT.ASSIGNEE' | translate&#125;&#125;<span class="tag">&lt;/<span class="name">label</span>&gt;</span>  </span><br><span class="line">           <span class="comment">&lt;!--                      &lt;input type="text" id="assigneeField" class="form-control" ng-model="assignment.assignee" placeholder="&#123;&#123;'PROPERTY.ASSIGNMENT.ASSIGNEE_PLACEHOLDER' | translate&#125;&#125;" /&gt;--&gt;</span>  </span><br><span class="line">           <span class="tag">&lt;<span class="name">select</span> <span class="attr">id</span>=<span class="string">"assigneeField"</span> <span class="attr">ng-model</span>=<span class="string">"assignment.assignee"</span> <span class="attr">class</span>=<span class="string">"form-control"</span> <span class="attr">placeholder</span>=<span class="string">"&#123;&#123;'PROPERTY.ASSIGNMENT.ASSIGNEE_PLACEHOLDER' | translate&#125;&#125;"</span>&gt;</span>  </span><br><span class="line">               <span class="tag">&lt;<span class="name">option</span> <span class="attr">ng-repeat</span>=<span class="string">"item in myTestList"</span> <span class="attr">ng-value</span>=<span class="string">"&#123;&#123;item.roleName&#125;&#125;"</span>&gt;</span>&#123;&#123;item.roleName&#125;&#125;<span class="tag">&lt;/<span class="name">option</span>&gt;</span>  </span><br><span class="line">           <span class="tag">&lt;/<span class="name">select</span>&gt;</span>   <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">           <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>被注释掉的部分就是原本的Input text输入框。这里修改为是用下拉框，并且后台提供接口查询当前系统的所有角色数据。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@RequestMapping</span>(value = <span class="string">"/editor/systemRoleNames"</span>, method = RequestMethod.GET, produces = <span class="string">"application/json;charset=utf-8"</span>)  </span><br><span class="line"><span class="meta">@ResponseBody</span>  </span><br><span class="line"><span class="function"><span class="keyword">public</span> AjaxResult <span class="title">systemRoleNames</span><span class="params">()</span> </span>&#123;  </span><br><span class="line">    List&lt;Role&gt; roles = service.listRole();  </span><br><span class="line">    <span class="keyword">return</span> AjaxResult.success(roles);  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="10-3-10-最终检查"><a href="#10-3-10-最终检查" class="headerlink" title="10.3.10 最终检查"></a>10.3.10 最终检查</h3><p>最后访问<code>/editor</code> 接口查看是否正常。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230210151955.png" alt="最终检查"></p>
<p>完成上面那一套之后，如果出现如上页面，说明web编辑器集成成功。</p>
<blockquote>
<p>毋庸置疑，这里截图为未隐藏不必要菜单版本。</p>
</blockquote>
<h2 id="10-4-可能遇到的问题"><a href="#10-4-可能遇到的问题" class="headerlink" title="10.4 可能遇到的问题"></a>10.4 可能遇到的问题</h2><h3 id="10-4-1-Factory-method-‘springProcessEngineConfiguration’-threw-exception-nested-exception-is-java-io-FileNotFoundException-class-path-resource-processes-cannot-be-resolved-to-URL-because-it-does-not-exist"><a href="#10-4-1-Factory-method-‘springProcessEngineConfiguration’-threw-exception-nested-exception-is-java-io-FileNotFoundException-class-path-resource-processes-cannot-be-resolved-to-URL-because-it-does-not-exist" class="headerlink" title="10.4.1 Factory method ‘springProcessEngineConfiguration’ threw exception; nested exception is java.io.FileNotFoundException: class path resource [processes/] cannot be resolved to URL because it does not exist"></a>10.4.1 Factory method ‘springProcessEngineConfiguration’ threw exception; nested exception is java.io.FileNotFoundException: class path resource [processes/] cannot be resolved to URL because it does not exist</h3><p>其实英文已经说的很明显了，需要添加一个<strong>processes文件夹</strong>在resources的目录。可以通过在<code>yml</code>配置当中将<code>check-process-definitions: false</code> 去除强制检查。<br><code>process-definition-location-prefix</code>可以修改模型图的存储位置。</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># Spring配置</span></span><br><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="comment"># activiti 模块</span></span><br><span class="line">  <span class="comment"># 解决启动报错：class path resource [processes/] cannot be resolved to URL because it does not exist</span></span><br><span class="line">  <span class="attr">activiti:</span></span><br><span class="line">    <span class="attr">check-process-definitions:</span> <span class="literal">false</span></span><br></pre></td></tr></table></figure>



<h3 id="10-4-2-application-yml-配置"><a href="#10-4-2-application-yml-配置" class="headerlink" title="10.4.2 application.yml 配置"></a>10.4.2 application.yml 配置</h3><p>Activity 6 的参考配置如下：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">activiti:</span>  </span><br><span class="line"><span class="comment">#    flase：       默认值。activiti在启动时，会对比数据库表中保存的版本，如果没有表或者版本不匹配，将抛出异常。（生产环境常用）</span></span><br><span class="line"><span class="comment">#    true：        activiti会对数据库中所有表进行更新操作。如果表不存在，则自动创建。（开发时常用）</span></span><br><span class="line">  <span class="attr">database-schema-update:</span> <span class="literal">true</span>  </span><br><span class="line">    <span class="comment"># 解决启动报错：class path resource [processes/] cannot be resolved to URL because it does not exist</span></span><br><span class="line">  <span class="attr">check-process-definitions:</span> <span class="literal">true</span> </span><br><span class="line">  <span class="comment"># 修改模型图的存储位置 </span></span><br><span class="line">  <span class="attr">process-definition-location-prefix:</span> <span class="string">classpath:/processes/</span>  </span><br><span class="line">  <span class="comment">#    full: 性能较差，记录所有实例和变量细节变化，最完整的历史记录，如果需要日后跟踪详细可以开启full</span></span><br><span class="line">  <span class="attr">history-level:</span> <span class="string">full</span></span><br></pre></td></tr></table></figure>



<h3 id="10-4-3-java-lang-IllegalArgumentException-Could-not-find-class-org-springframework-boot-autoconfigure-security-SecurityAutoConfiguration"><a href="#10-4-3-java-lang-IllegalArgumentException-Could-not-find-class-org-springframework-boot-autoconfigure-security-SecurityAutoConfiguration" class="headerlink" title="10.4.3 java.lang.IllegalArgumentException: Could not find class [org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration]"></a>10.4.3 java.lang.IllegalArgumentException: Could not find class [org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration]</h3><p>这个报错很简单，意思是说找不到Spring的安全管理类。通常情况下只需要把SpringBoot的Security排除或者Activity的Security排除即可。</p>
<p>比如下面的方式排除Activity的依赖。（个人建议）</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@SpringBootApplication</span>(exclude = &#123; </span><br><span class="line">        org.activiti.spring.boot.SecurityAutoConfiguration<span class="class">.<span class="keyword">class</span>&#125;)</span></span><br><span class="line"><span class="class"><span class="title">public</span> <span class="title">class</span> <span class="title">SaAdminWebApplication</span> </span>&#123;</span><br><span class="line">	<span class="comment">// ....</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>但是如果项目中没有使用Spring Securrity，那么规避此问题请继续看下一个解决方案。</p>
<h3 id="10-4-4-Failed-to-process-import-candidates-for-configuration-class-com-sa-SaAdminImplApplication-nested-exception-is-java-io-FileNotFoundException-class-path-resource-org-springframework-security-config-annotation-authentication-configurers-GlobalAuthenticationConfigurerAdapter-class-cannot-be-opened-because-it-does-not-exist"><a href="#10-4-4-Failed-to-process-import-candidates-for-configuration-class-com-sa-SaAdminImplApplication-nested-exception-is-java-io-FileNotFoundException-class-path-resource-org-springframework-security-config-annotation-authentication-configurers-GlobalAuthenticationConfigurerAdapter-class-cannot-be-opened-because-it-does-not-exist" class="headerlink" title="10.4.4 Failed to process import candidates for configuration class [com.sa.SaAdminImplApplication]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/security/config/annotation/authentication/configurers/GlobalAuthenticationConfigurerAdapter.class] cannot be opened because it does not exist"></a>10.4.4 Failed to process import candidates for configuration class [com.sa.SaAdminImplApplication]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/security/config/annotation/authentication/configurers/GlobalAuthenticationConfigurerAdapter.class] cannot be opened because it does not exist</h3><p>这个报错是在加入Activity之后，Activity旧版本的安全管理类和SpringBoot的安全管理产生的冲突。如果出现类似报错，请检查是否存在下面的依赖。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-security<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span>  </span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>如果项目中并没有用Security的任何依赖，那么排除依赖的处理方式启动还是报错，由于集成的项目使用了Shiro，于是决定在<code>SaAdminWebApplication</code>中进行如下设置：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@SpringBootApplication</span>(exclude = &#123; </span><br><span class="line">        org.activiti.spring.boot.SecurityAutoConfiguration<span class="class">.<span class="keyword">class</span>,  </span></span><br><span class="line"><span class="class"><span class="title">org</span>.<span class="title">springframework</span>.<span class="title">boot</span>.<span class="title">autoconfigure</span>.<span class="title">security</span>.<span class="title">servlet</span>.<span class="title">SecurityAutoConfiguration</span>.<span class="title">class</span>  </span></span><br><span class="line"><span class="class">&#125;)</span></span><br><span class="line"><span class="class"><span class="title">public</span> <span class="title">class</span> <span class="title">Application</span> </span>&#123;</span><br><span class="line">	<span class="comment">// ....</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>如上配置之后最后项目成功启动。</p>
<h3 id="10-4-5-可视化编辑器的页面白板问题处理"><a href="#10-4-5-可视化编辑器的页面白板问题处理" class="headerlink" title="10.4.5 可视化编辑器的页面白板问题处理"></a>10.4.5 可视化编辑器的页面白板问题处理</h3><p>集成在线可视化流程图编辑器的时候，首次跳转<code>modeler.html</code> 页面可能会出现下面的错误，整个页面都是一块“白板”。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230210145809.png" alt=""></p>
<p>这是初学者集成比较容易犯的错误，遇到这样的画面，可以在<code>modeler.html</code>页面的浏览器中打开F12，在“Network”当中可以看到有几个请求报错爆红。这几个接口的获取分别是 <strong>获取模型JSON信息</strong>以及 <strong>获取模型自身JSON数据</strong>。关键问题是集成WEB版本的流程编辑器之后，<strong>访问开源的modeler.html的编辑器页面，页面会自动发送请求</strong>。为了节省读者时间，这里省略了查找请求接口调用脚本的过程。</p>
<p>我们可以阅读 <code>${项目路径下的static文件夹}$\model\manage\editor-app\app-cfg.js</code>这里的配置，文件内容如下，这里的<code>contextRoot</code>对应上下文信息<code>activiti-explorer</code>在请求中出现了。</p>
<p><strong>app-cfg.js</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">'use strict'</span>;  </span><br><span class="line">  </span><br><span class="line"><span class="keyword">var</span> ACTIVITI = ACTIVITI || &#123;&#125;;  </span><br><span class="line">  </span><br><span class="line">ACTIVITI.CONFIG = &#123;  </span><br><span class="line">   <span class="string">'contextRoot'</span> : <span class="string">'activiti-explorer'</span>,  </span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230210151753.png" alt="app-cfg.js"></p>
<p>这个 contextRoot 的设置又有什么含义？举个例子，这里访问到编辑器的请求为<code>/activiti-explorer/model/7503/json</code>，<strong>7503</strong> 对应模型的唯一ID通过数据库可以查询出来，<code>/activiti-explorer</code>则对应了上下文部分。</p>
<p>这里可能会问了，上下文是知道了，但是怎么知道脚本在哪里发送请求的。这里介绍一下IDEA搜索技巧，我们全局搜索<code>contextRoot</code>，最终可以找到名为<code>url-config.js</code>的文件的相关配置。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230423155906.png" alt="contextRoot搜索"></p>
<p>文件开头有一大段注释，根据代码内容可以看到这里就是整个Activity前端需要的调用接口的全局配置。</p>
<blockquote>
<p>getRoleNames为业务需求添加。</p>
</blockquote>
<p><code>url-config.js</code> 文件内容如下：</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> KISBPM = KISBPM || &#123;&#125;;  </span><br><span class="line">  </span><br><span class="line">KISBPM.URL = &#123;  </span><br><span class="line">  </span><br><span class="line">    getModel: <span class="function"><span class="keyword">function</span>(<span class="params">modelId</span>) </span>&#123;  </span><br><span class="line">        <span class="keyword">return</span> ACTIVITI.CONFIG.contextRoot + <span class="string">'/model/'</span> + modelId + <span class="string">'/json'</span>;  </span><br><span class="line">    &#125;,  </span><br><span class="line">  </span><br><span class="line">    getStencilSet: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;  </span><br><span class="line">        <span class="keyword">return</span> ACTIVITI.CONFIG.contextRoot + <span class="string">'/editor/stencilset?version='</span> + <span class="built_in">Date</span>.now();  </span><br><span class="line">    &#125;,  </span><br><span class="line">  </span><br><span class="line">    getRoleNames: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;  </span><br><span class="line">        <span class="keyword">return</span> ACTIVITI.CONFIG.contextRoot + <span class="string">'/editor/systemRoleNames?version='</span> + <span class="built_in">Date</span>.now();  </span><br><span class="line">    &#125;,  </span><br><span class="line">  </span><br><span class="line">    putModel: <span class="function"><span class="keyword">function</span>(<span class="params">modelId</span>) </span>&#123;  </span><br><span class="line">        <span class="keyword">return</span> ACTIVITI.CONFIG.contextRoot + <span class="string">'/model/'</span> + modelId + <span class="string">'/save'</span>;  </span><br><span class="line">    &#125;  </span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>



<h3 id="10-4-6-补充：集成到实际项目的注意事项"><a href="#10-4-6-补充：集成到实际项目的注意事项" class="headerlink" title="10.4.6 补充：集成到实际项目的注意事项"></a>10.4.6 补充：集成到实际项目的注意事项</h3><p>最为推荐的方式建议找一个能正常跑的SpringBoot项目，对照项目一个个添加Activity的相关依赖，遇到报错根据错误去搜索解决。这种方式也可以节省下大量的试错而浪费的时间。</p>
<p>什么意思呢？这里回到依赖部分，比如下面的依赖我们可以先只添加一个，打包依赖之后直接部署项目查看是否和已有的依赖存在冲突，也可以利用IDEA工具来解决依赖冲突问题。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- Activity 依赖 --&gt;</span>  </span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.activiti<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>activiti-json-converter<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">version</span>&gt;</span>6.0.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span>  </span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span>  </span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.activiti<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>activiti-bpmn-layout<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">version</span>&gt;</span>6.0.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span>  </span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span>  </span><br><span class="line">  </span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.xmlgraphics<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>batik-transcoder<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">version</span>&gt;</span>1.10<span class="tag">&lt;/<span class="name">version</span>&gt;</span>  </span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.xmlgraphics<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>batik-codec<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span>  </span><br><span class="line">   <span class="tag">&lt;<span class="name">version</span>&gt;</span>1.9<span class="tag">&lt;/<span class="name">version</span>&gt;</span>  </span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>至此我们把Activity 成功集成到项目当中，下面开始了解Activity的具体细节。</p>
<h1 id="十一、Activity-设计流程图（各种组件，如连线、用户任务、网关）"><a href="#十一、Activity-设计流程图（各种组件，如连线、用户任务、网关）" class="headerlink" title="十一、Activity 设计流程图（各种组件，如连线、用户任务、网关）"></a>十一、Activity 设计流程图（各种组件，如连线、用户任务、网关）</h1><p>我们将Activity的web版本流程设计编辑器集成之后，前后端此时就可以完成基本的模型新增和编辑操，在介绍具体的代码增删改查之前，我们先了解如何使用Activity 流程设计器。</p>
<p>下面介绍最简单的基础的模型绘制和使用。</p>
<blockquote>
<p>注意演示版本为最为简单的工作流版本，更为复杂的工作流程设计可以将所有组件展示之后自行了解。</p>
</blockquote>
<h2 id="11-1-各种组件"><a href="#11-1-各种组件" class="headerlink" title="11.1 各种组件"></a>11.1 各种组件</h2><p>注意下面的图中个人隐藏掉大部分按钮，篇幅有限，这里只介绍几个最简单和基础的功能。</p>
<h3 id="11-2-0-主界面"><a href="#11-2-0-主界面" class="headerlink" title="11.2.0 主界面"></a>11.2.0 主界面</h3><p>主界面分为四个部分：左侧为功能按钮区域，顶部是一些针对流程图设计的快捷功能，比如剪切，粘贴，复制，还有放大和缩小等。右边空白区域为绘制流程图的区域，我们需要从左侧菜单拖拽节点到右侧绘制流程图，最后是底部的节点描述区域，其中可以设置节点的名称，节点的文档描述，对于连线或者用户活动，则可以设置流程变量或者分配责任人等操作。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424142300.png" alt="image.png"></p>
<p>回到左侧菜单，这里先介绍必备的开始节点和结束节点这两个组件。</p>
<h3 id="11-2-1-Start-Events"><a href="#11-2-1-Start-Events" class="headerlink" title="11.2.1 Start Events"></a>11.2.1 Start Events</h3><p>开始事件：开始事件并不是一个活动，它仅仅代表一个节点的开始。也是一个流程实例的起点开始节点，仅仅可以设置节点名称以及节点的备注和文档描述（对应底部部分）。开始事件多数情况下仅有一个。</p>
<h3 id="11-2-2-EndEvents"><a href="#11-2-2-EndEvents" class="headerlink" title="11.2.2 EndEvents"></a>11.2.2 EndEvents</h3><p>结束事件：结束事件不一定和开始事件一样一一对应的，在复杂的工作流模型中，可以根据不同的分支进入出现多个结束节点。</p>
<h3 id="11-2-3-插曲：最简单的工作流"><a href="#11-2-3-插曲：最简单的工作流" class="headerlink" title="11.2.3 插曲：最简单的工作流"></a>11.2.3 插曲：最简单的工作流</h3><p>Activity最简单的工作流实际上是像下面这样，直接把开始节点连接到结束节点，虽然它没有任何实际意义，但是它确实可以正确部署（不会产生报错和异常），并且成功部署为一个可以运作的工作流。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424143929.png" alt="image.png"></p>
<p>下面是保存操作，save之后即可保存，修改过程可以编辑名称和唯一标识。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424144024.png" alt="image.png"></p>
<h3 id="11-2-4-User-Task"><a href="#11-2-4-User-Task" class="headerlink" title="11.2.4 User Task"></a>11.2.4 User Task</h3><p>用户任务是最为简单也是最常用的的一种活动节点，对应我们日常工作的业务流转或者任务流转，用户任务同样可以设置节点名称和文档描述。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424150040.png" alt="image.png"></p>
<p>除此之外，用户活动作为活动节点，可以设置负责人：</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424150149.png" alt="image.png"></p>
<p>这里assignment 下拉选择对应的负责人即可。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424152125.png" alt="image.png"></p>
<h2 id="11-2-连线"><a href="#11-2-连线" class="headerlink" title="11.2 连线"></a>11.2 连线</h2><p>连线目前项目仅仅使用箭头连线，箭头连线基本可以覆盖99% 的使用场景，所以其他两种连线方式这里就忽略了。</p>
<blockquote>
<p>注意：连线实际上输入流程变量条件表达式，实现同一个“出口”进入不同下一个活动节点功能，通过连接的表达式也可以实现各种细节判断。</p>
</blockquote>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424153712.png" alt="image.png"></p>
<blockquote>
<p>后续此部分可以补充和完善。</p>
</blockquote>
<h2 id="11-3-用户任务"><a href="#11-3-用户任务" class="headerlink" title="11.3 用户任务"></a>11.3 用户任务</h2><p>User Task只是活动分类的一个细节分支，实际上除开用户任务之外很多用户任务。同样因为项目需求暂时没有更多设计流程上更为复杂的需求，所以一并忽略了。</p>
<blockquote>
<p>后续此部分可以补充和完善。</p>
</blockquote>
<h2 id="11-4-网关"><a href="#11-4-网关" class="headerlink" title="11.4 网关"></a>11.4 网关</h2><p>虽然项目中并没有用到任何网关组件，但是网关是实现复杂组件的前提这里一并补充介绍。</p>
<h3 id="11-4-1-什么是排他网关"><a href="#11-4-1-什么是排他网关" class="headerlink" title="11.4.1 什么是排他网关?"></a>11.4.1 什么是排他网关?</h3><p>排他网关，用来在流程中实现决策。 当流程执行到这个网关，所有分支都会判断条件是否为true，如果为true则执行该分支，否则执行另外的条件分支。</p>
<p>注意：排他网关只会选择一个为true的分支执行。<strong>如果有两个分支条件都为true，排他网关会选择id值较小的一条分支去执行</strong>，当然不建议实际使用过程中去“碰瓷”这个条件。</p>
<h4 id="为什么要用排他网关？"><a href="#为什么要用排他网关？" class="headerlink" title="为什么要用排他网关？"></a>为什么要用排他网关？</h4><p>不用排他网关也可以实现分支，但是在连线设置condition条件的缺点如果条件都不满足，流程就异常结束了（或者说看起来像是永远挂起）。</p>
<blockquote>
<p>如：在<strong>连线的condition</strong>条件上设置分支条件。</p>
</blockquote>
<p>在下面的案例当中，排他网关起到了分支 if/else 判断的作用。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424160557.png" alt="为什么要用排他网关"></p>
<p>需要注意，<strong>如果从网关出去的线所有条件都不满足则系统抛出异常</strong>。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">org.activiti.engine.ActivitiException: No outgoing sequence flow of the exclusive gateway <span class="string">'exclusivegateway1'</span> could be selected <span class="keyword">for</span> continuing the process</span><br><span class="line">   at org.activiti.engine.impl.bpmn.behavior.ExclusiveGatewayActivityBehavior.leave(ExclusiveGatewayActivityBehavior.java:<span class="number">85</span>)</span><br></pre></td></tr></table></figure>

<p>排他网关的图标通常是一个 X。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424160638.png" alt="image.png"></p>
<h3 id="11-4-2-并行网关ParallelGateway"><a href="#11-4-2-并行网关ParallelGateway" class="headerlink" title="11.4.2 并行网关ParallelGateway"></a>11.4.2 并行网关ParallelGateway</h3><p><strong>并行网关允许将流程分成多条分支</strong>，也可以把多条分支汇聚到一起，并行网关的功能是基于进入和外出顺序流的。</p>
<blockquote>
<p>分支汇聚的术语叫做 fork/join，和 Java的 fork / join 概念类似。</p>
</blockquote>
<p>fork分支：并行之后的所有外出顺序流，为每个顺序流都创建一个并发分支。</p>
<p>join汇聚：所有到达并行网关，在此等待的进入分支， 直到所有进入顺序流的分支都到达以后， 流程就会通过汇聚网关。</p>
<p><strong>与其他网关的主要区别是，并行网关不会解析条件。 即使顺序流中定义了条件，也会被忽略。</strong></p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424160915.png" alt="image.png"></p>
<p>技术经理和项目经理是<strong>两个execution分支</strong>，在act_ru_execution表有两条记录分别是技术经理和项目经理，act_ru_execution 还有一条记录表示该流程实例。</p>
<p>待技术经理和项目经理任务全部完成，在汇聚点汇聚，通过parallelGateway并行网关。</p>
<p>fork/join 的工作模式经常用在多个人共同完成一个任务的时候使用，比如一个方案要两个人都完成签字审批之后才能进入到下一步。</p>
<p>并行网关的图案是十字架样式。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424161449.png" alt="image.png"></p>
<h3 id="11-4-3-什么是包含网关"><a href="#11-4-3-什么是包含网关" class="headerlink" title="11.4.3 什么是包含网关"></a>11.4.3 什么是包含网关</h3><p>包含网关可以看做是排他网关和并行网关的结合体。包含网关和排他网关一样，可以在外出顺序流上定义条件，包含网关会解析它们。</p>
<p>包含网关和排他网关的主要区别是<strong>包含网关可以选择多于一条顺序流</strong>，这和并行网关一样。包含网关的功能是基于进入和外出顺序流的：</p>
<p>分支：所有外出顺序流的条件都会被解析，结果为true的顺序流会以并行方式继续执行， 会为每个顺序流创建一个分支。</p>
<p>汇聚：所有并行分支到达包含网关，会进入等待状态， 直到每个包含流程token的进入顺序流的分支都到达。 这是与并行网关的最大不同。换句话说，包含网关只会等待被选中执行了的进入顺序流。 在汇聚之后，流程会穿过包含网关继续执行。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230425172943.png" alt="image.png"></p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230425172958.png" alt="image.png"></p>
<h3 id="11-4-4-事件网关-EventGateway"><a href="#11-4-4-事件网关-EventGateway" class="headerlink" title="11.4.4 事件网关 EventGateway"></a>11.4.4 事件网关 EventGateway</h3><p>事件网关必须有两条或以上外出顺序流；</p>
<p>事件网关允许根据事件判断流向。网关的每个外出顺序流都要连接到一个中间捕获事件。 当流程到达一个基于事件网关，网关会进入等待状态：暂停执行。与此同时，会为每个外出顺序流创建相对的事件订阅。</p>
<p>事件网关的外出顺序流和普通顺序流不同，这些顺序流不会真的”执行”， 相反它们让流程引擎去决定执行到事件网关的流程需要订阅哪些事件。 要考虑以下条件：</p>
<p>使用事件网关要考虑以下条件：</p>
<ol>
<li>基于事件网关必须有两条或以上外出顺序流；</li>
<li>基于事件网关后，只能使用intermediateCatchEvent类型（activiti不支持基于事件网关后连接ReceiveTask。）；</li>
<li>连接到事件网关的中间捕获事件必须只有一个入口顺序流。</li>
</ol>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230425174124.png" alt="image.png"></p>
<p>intermediateCatchEvent 类型选择如下：</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230425174513.png" alt="image.png"></p>
<p>intermediateCatchEvent支持的事件类型：</p>
<ul>
<li>Message Event: 消息事件</li>
<li>Singal Event： 信号事件</li>
<li>Timer Event： 定时事件</li>
</ul>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230425174456.png" alt="image.png"></p>
<p>使用事件网关定义流程：</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230425174234.png" alt="image.png"></p>
<h1 id="十二、如何使用-Activity-进行开发"><a href="#十二、如何使用-Activity-进行开发" class="headerlink" title="十二、如何使用 Activity 进行开发"></a>十二、如何使用 Activity 进行开发</h1><p>当Activity集成到项目并且了解了如何利用WEB的模型编辑器绘制模型之后，我们下面要正式开始Activity工作流的开发工作。</p>
<p>涉及具体的业务之前，我们先介绍所有业务都能够通用部分。</p>
<h2 id="12-1-流程定义增删改查"><a href="#12-1-流程定义增删改查" class="headerlink" title="12.1 流程定义增删改查"></a>12.1 流程定义增删改查</h2><p>流程定义增删改查包含两个部分，一个是模型设计，另一个是部署流程。这部分内容涉及到纯粹的代码。通过了解增删改查Activity的审批流模型代码，可以帮助我们熟悉API使用。</p>
<h3 id="12-1-1-添加新模型代码"><a href="#12-1-1-添加新模型代码" class="headerlink" title="12.1.1 添加新模型代码"></a>12.1.1 添加新模型代码</h3><p>新增模型我们需要传输下面几个变量：</p>
<ul>
<li>modelName 模型名称：因为实际存储为xml，所以不能有特殊字符，建议只允许大小写字母。不允许重名</li>
<li>modelFlag 模型标识：类似模型的唯一标识，同样监狱不要有特殊字符，建议只允许大小写字母。</li>
<li>classify：模型分类，可选，用于使用过程中对于业务模型进行分类</li>
<li>description：描述信息，可选。</li>
<li>version：每次新部署的模型就是一个新的版本，初始部署的模型版本为1，之后每部署一次都将会+1。类似乐观锁</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span>  </span><br><span class="line"><span class="function"><span class="keyword">public</span> AjaxResult <span class="title">addNewModel</span><span class="params">(AddModelRequestDto addModelRequestDto)</span> </span>&#123;  </span><br><span class="line">    Matcher matcher = ONLY_LETTER_OR_NUMBER_PATTERN.matcher(addModelRequestDto.getModelFlag());  </span><br><span class="line">    <span class="keyword">if</span>(!matcher.matches())&#123;  </span><br><span class="line">        <span class="keyword">return</span> AjaxResult.error(<span class="string">"Approval Flow Model identification can only consist of upper and lower case letters."</span>);  </span><br><span class="line">    &#125;  </span><br><span class="line">    Model model = repositoryService.newModel();  </span><br><span class="line">    model.setCategory(addModelRequestDto.getClassify());  </span><br><span class="line">    model.setKey(addModelRequestDto.getModelFlag());  </span><br><span class="line">    ObjectNode modelNode = objectMapper.createObjectNode();  </span><br><span class="line">    modelNode.put(ModelDataJsonConstants.MODEL_NAME, addModelRequestDto.getModelName());  </span><br><span class="line">    modelNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, addModelRequestDto.getDescription());  </span><br><span class="line">    modelNode.put(ModelDataJsonConstants.MODEL_REVISION, addModelRequestDto.getVersion());  </span><br><span class="line">    model.setMetaInfo(modelNode.toString());  </span><br><span class="line">    model.setName(addModelRequestDto.getModelName());  </span><br><span class="line">    model.setVersion(addModelRequestDto.getVersion());  </span><br><span class="line">    ModelQuery modelQuery = repositoryService.createModelQuery();  </span><br><span class="line">    List&lt;Model&gt; list = modelQuery.modelKey(addModelRequestDto.getModelFlag()).list();  </span><br><span class="line">    <span class="keyword">if</span> (<span class="number">0</span> &lt; CollUtil.size(list)) &#123;  </span><br><span class="line">        <span class="keyword">return</span> AjaxResult.error(String.format(<span class="string">"Approval Flow Model identification [%s] already exists"</span>, addModelRequestDto.getModelFlag()));  </span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;  </span><br><span class="line">        <span class="comment">// 保存模型到act_re_model表  </span></span><br><span class="line">        repositoryService.saveModel(model);  </span><br><span class="line">        HashMap&lt;String, Object&gt; content = <span class="keyword">new</span> HashMap();  </span><br><span class="line">        content.put(<span class="string">"resourceId"</span>, model.getId());  </span><br><span class="line">        HashMap&lt;String, String&gt; properties = <span class="keyword">new</span> HashMap();  </span><br><span class="line">        properties.put(<span class="string">"process_id"</span>, addModelRequestDto.getModelFlag());  </span><br><span class="line">        properties.put(<span class="string">"name"</span>, addModelRequestDto.getModelName());  </span><br><span class="line">        properties.put(<span class="string">"category"</span>, addModelRequestDto.getClassify());  </span><br><span class="line">        content.put(<span class="string">"properties"</span>, properties);  </span><br><span class="line">        HashMap&lt;String, String&gt; stencilset = <span class="keyword">new</span> HashMap();  </span><br><span class="line">        stencilset.put(<span class="string">"namespace"</span>, NAME_SPACE);  </span><br><span class="line">        content.put(<span class="string">"stencilset"</span>, stencilset);  </span><br><span class="line">        <span class="comment">// 保存模型文件到 act_ge_bytearray 表  </span></span><br><span class="line">        <span class="keyword">try</span> &#123;  </span><br><span class="line">            repositoryService.addModelEditorSource(model.getId(), objectMapper.writeValueAsBytes(content));  </span><br><span class="line">        &#125; <span class="keyword">catch</span> (JsonProcessingException e) &#123;  </span><br><span class="line">            log.error(<span class="string">"append Approval Flow Model editor error:"</span>, e);  </span><br><span class="line">            <span class="keyword">return</span> AjaxResult.error();  </span><br><span class="line">        &#125;  </span><br><span class="line">        <span class="keyword">return</span> AjaxResult.success(model);  </span><br><span class="line">    &#125;  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>简单理解是将数据封装为Hashmap，最后通过jackson转为字节数据写入到Activity的数据表即可。数据库的最终表现形式如下：</p>
<p><strong>act_re_model</strong></p>
<table>
<thead>
<tr>
<th>id_</th>
<th>rev_</th>
<th>name_</th>
<th>key_</th>
<th>category_</th>
<th>create_time_</th>
<th>last_update_time_</th>
<th>version_</th>
<th>meta_info_</th>
<th>deployment_id_</th>
<th>editor_source_value_id_</th>
<th>editor_source_extra_value_id_</th>
<th>tenant_id_</th>
</tr>
</thead>
<tbody><tr>
<td>22547</td>
<td>11</td>
<td>QAZX</td>
<td>QAZX</td>
<td>QAZX</td>
<td>########</td>
<td>########</td>
<td>4</td>
<td>{“name”:”QAZX”,”description”:”QAZX”,”revision”:null}</td>
<td>22548</td>
<td>22549</td>
<td></td>
<td></td>
</tr>
<tr>
<td>15001</td>
<td>7</td>
<td>MerchantFreeze</td>
<td>MerchantFreeze</td>
<td>MerchantFreeze</td>
<td>########</td>
<td>########</td>
<td>2</td>
<td>{“name”:”MerchantFreeze”,”description”:”MerchantFreeze”,”revision”:null}</td>
<td>112501</td>
<td>15002</td>
<td>15003</td>
<td></td>
</tr>
<tr>
<td>135043</td>
<td>5</td>
<td>RiskRulesSetting</td>
<td>RiskRulesSetting</td>
<td>RiskRulesSetting</td>
<td>########</td>
<td>########</td>
<td>2</td>
<td>{“name”:”RiskRulesSetting”,”description”:”RiskRulesSetting”,”revision”:null}</td>
<td>135046</td>
<td>135044</td>
<td>135045</td>
<td></td>
</tr>
<tr>
<td>155044</td>
<td>5</td>
<td>MerchantFee</td>
<td>MerchantFee</td>
<td>MerchantFee</td>
<td>########</td>
<td>########</td>
<td>2</td>
<td>{“name”:”MerchantFee”,”description”:”MerchantFee”,”revision”:null}</td>
<td>155047</td>
<td>155045</td>
<td>155046</td>
<td></td>
</tr>
<tr>
<td>127544</td>
<td>9</td>
<td>IP</td>
<td>IP</td>
<td>IP</td>
<td>########</td>
<td>########</td>
<td>4</td>
<td>{“name”:”IP”,”description”:”IP”,”revision”:null}</td>
<td>175044</td>
<td>127545</td>
<td>127546</td>
<td></td>
</tr>
<tr>
<td>220001</td>
<td>5</td>
<td>MerchantVaRefund</td>
<td>MerchantVaRefund</td>
<td>MerchantVaRefund</td>
<td>########</td>
<td>########</td>
<td>2</td>
<td>{“name”:”MerchantVaRefund”,”description”:”MerchantVaRefund”,”revision”:null}</td>
<td>220004</td>
<td>220002</td>
<td>220003</td>
<td></td>
</tr>
<tr>
<td>202592</td>
<td>5</td>
<td>MerchantOpenAccount</td>
<td>MerchantOpenAccount</td>
<td>MerchantOpenAccount</td>
<td>########</td>
<td>########</td>
<td>2</td>
<td>{“name”:”MerchantOpenAccount”,”description”:”MerchantOpenAccount”,”revision”:null}</td>
<td>202595</td>
<td>202593</td>
<td>202594</td>
<td></td>
</tr>
</tbody></table>
<h3 id="12-1-2-查询所有流程模型"><a href="#12-1-2-查询所有流程模型" class="headerlink" title="12.1.2 查询所有流程模型"></a>12.1.2 查询所有流程模型</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> List&lt;Model&gt; <span class="title">listModelAll</span><span class="params">()</span> </span>&#123;  </span><br><span class="line">    ModelQuery modelQuery = repositoryService.createModelQuery();  </span><br><span class="line">    <span class="keyword">return</span> modelQuery.orderByCreateTime().desc().latestVersion().orderByCreateTime().desc().list();  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h3 id="12-1-3-分页查询流程模型"><a href="#12-1-3-分页查询流程模型" class="headerlink" title="12.1.3 分页查询流程模型"></a>12.1.3 分页查询流程模型</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span>  </span><br><span class="line"><span class="function"><span class="keyword">public</span> List&lt;Model&gt; <span class="title">listModelPage</span><span class="params">(Integer pageNum, Integer rows,ModelRequestDto modelRequestDto)</span> </span>&#123;  </span><br><span class="line">    ModelQuery modelQuery = repositoryService.createModelQuery();  </span><br><span class="line">    <span class="keyword">if</span> (StringUtils.isNotEmpty(modelRequestDto.getKey())) &#123;  </span><br><span class="line">        modelQuery.modelKey(StrUtil.trim(modelRequestDto.getKey()));  </span><br><span class="line">    &#125;  </span><br><span class="line">    <span class="keyword">if</span> (StringUtils.isNotEmpty(modelRequestDto.getName())) &#123;  </span><br><span class="line">        modelQuery.modelNameLike(StrUtil.trim(modelRequestDto.getName()));  </span><br><span class="line">    &#125;  </span><br><span class="line">    PageHelper.startPage(pageNum, rows);  </span><br><span class="line">    <span class="keyword">return</span> modelQuery.orderByCreateTime().desc().listPage(pageNum, rows);  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h3 id="12-1-4-删除流程模型"><a href="#12-1-4-删除流程模型" class="headerlink" title="12.1.4 删除流程模型"></a>12.1.4 删除流程模型</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span>  </span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">deleteModel</span><span class="params">(String modelId)</span> </span>&#123;  </span><br><span class="line">    repositoryService.deleteModel(modelId);  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h3 id="12-1-5-导出模型"><a href="#12-1-5-导出模型" class="headerlink" title="12.1.5 导出模型"></a>12.1.5 导出模型</h3><p>有时候需要导出model文件，我们可以用下面的代码实现，<code>.bpmn20.xml</code>这个20并不是写错了，而是bpmn2.0规范要求的后缀，IDEA插件也会根据此后缀进行智能识别。</p>
<blockquote>
<p>换句话说就是后缀写错了识别不了。</p>
</blockquote>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span>  </span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">modelExport</span><span class="params">(String modelId, HttpServletResponse response)</span> <span class="keyword">throws</span> IOException </span>&#123;  </span><br><span class="line">    <span class="keyword">byte</span>[] modelData = repositoryService.getModelEditorSource(modelId);  </span><br><span class="line">    JsonNode jsonNode = objectMapper.readTree(modelData);  </span><br><span class="line">    BpmnModel bpmnModel = (<span class="keyword">new</span> BpmnJsonConverter()).convertToBpmnModel(jsonNode);  </span><br><span class="line">    <span class="keyword">byte</span>[] xmlBytes = (<span class="keyword">new</span> BpmnXMLConverter()).convertToXML(bpmnModel, <span class="string">"UTF-8"</span>);  </span><br><span class="line">    ByteArrayInputStream in = <span class="keyword">new</span> ByteArrayInputStream(xmlBytes);  </span><br><span class="line">    org.apache.poi.util.IOUtils.copy(in, response.getOutputStream());  </span><br><span class="line">    String filename = bpmnModel.getMainProcess().getId() + <span class="string">".bpmn20.xml"</span>;  </span><br><span class="line">    response.setHeader(<span class="string">"Content-Disposition"</span>,<span class="string">"attachment;filename="</span> + filename);  </span><br><span class="line">    response.setHeader(<span class="string">"content-Type"</span>, <span class="string">"application/xml"</span>);  </span><br><span class="line">    response.flushBuffer();  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h3 id="12-1-6-部署流程"><a href="#12-1-6-部署流程" class="headerlink" title="12.1.6 部署流程"></a>12.1.6 部署流程</h3><p>部署模型首先需要在资源库中找到对应的模型，转化为BpmnModel，之后需要创建部署工具设置相关参数之后执行部署。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span>  </span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">deploy</span><span class="params">(String modelId)</span> <span class="keyword">throws</span> IOException </span>&#123;  </span><br><span class="line">    Model model = repositoryService.getModel(modelId);  </span><br><span class="line">    <span class="keyword">byte</span>[] modelData = repositoryService.getModelEditorSource(modelId);  </span><br><span class="line">    JsonNode jsonNode = objectMapper.readTree(modelData);  </span><br><span class="line">    BpmnModel bpmnModel = (<span class="keyword">new</span> BpmnJsonConverter()).convertToBpmnModel(jsonNode);  </span><br><span class="line">    Deployment deploy = repositoryService.createDeployment().category(model.getCategory())  </span><br><span class="line">            .name(model.getName()).key(model.getKey())  </span><br><span class="line">            .addBpmnModel(String.format(<span class="string">"%s%s"</span>, model.getKey(), BPM20_XML), bpmnModel)  </span><br><span class="line">            .deploy();  </span><br><span class="line">    model.setDeploymentId(deploy.getId());  </span><br><span class="line">    <span class="keyword">int</span> deleteByModelDefId = saBusinessBindingService.deleteByModelDefId(deploy.getKey());  </span><br><span class="line">    log.info(<span class="string">"deleteByModelDefId =&gt; &#123;&#125;, row modified =&gt; &#123;&#125;"</span>, deploy.getKey(), deleteByModelDefId);  </span><br><span class="line">    repositoryService.saveModel(model);  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>之后是保存数据库当中。数据库的最终表现形式如下：</p>
<p><strong>act_re_deployment</strong></p>
<table>
<thead>
<tr>
<th>id_</th>
<th>name_</th>
<th>category_</th>
<th>key_</th>
<th>tenant_id_</th>
<th>deploy_time_</th>
<th>engine_version_</th>
</tr>
</thead>
<tbody><tr>
<td>22550</td>
<td>QAZX</td>
<td>QAZX</td>
<td>QAZX</td>
<td></td>
<td>########</td>
<td></td>
</tr>
<tr>
<td>27501</td>
<td>QAZX</td>
<td>QAZX</td>
<td>QAZX</td>
<td></td>
<td>########</td>
<td></td>
</tr>
<tr>
<td>112501</td>
<td>MerchantFreeze</td>
<td>MerchantFreeze</td>
<td>MerchantFreeze</td>
<td>########</td>
<td></td>
<td></td>
</tr>
<tr>
<td>135046</td>
<td>RiskRulesSetting</td>
<td>RiskRulesSetting</td>
<td>RiskRulesSetting</td>
<td>########</td>
<td></td>
<td></td>
</tr>
<tr>
<td>155047</td>
<td>MerchantFee</td>
<td>MerchantFee</td>
<td>MerchantFee</td>
<td>########</td>
<td></td>
<td></td>
</tr>
<tr>
<td>165001</td>
<td>regist</td>
<td>regist</td>
<td>regist</td>
<td></td>
<td>########</td>
<td></td>
</tr>
<tr>
<td>175044</td>
<td>IP</td>
<td>IP</td>
<td>IP</td>
<td></td>
<td>########</td>
<td></td>
</tr>
<tr>
<td>180047</td>
<td>regist</td>
<td>regist</td>
<td>regist</td>
<td></td>
<td>########</td>
<td></td>
</tr>
<tr>
<td>202595</td>
<td>MerchantOpenAccount</td>
<td>MerchantOpenAccount</td>
<td>MerchantOpenAccount</td>
<td>########</td>
<td></td>
<td></td>
</tr>
<tr>
<td>220004</td>
<td>MerchantVaRefund</td>
<td>MerchantVaRefund</td>
<td>MerchantVaRefund</td>
<td>########</td>
<td></td>
<td></td>
</tr>
<tr>
<td>225091</td>
<td>regist</td>
<td>regist</td>
<td>regist</td>
<td></td>
<td>########</td>
<td></td>
</tr>
</tbody></table>
<h3 id="12-1-7-业务绑定"><a href="#12-1-7-业务绑定" class="headerlink" title="12.1.7 业务绑定"></a>12.1.7 业务绑定</h3><p>业务绑定实现了工作流和业务标识的绑定操作，在具体的编码过程中可以通过业务绑定标识找到指定模型，并且根据部署的模型构建不同的流程实例。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Override</span>  </span><br><span class="line"><span class="meta">@Transactional</span>(rollbackFor = Exception<span class="class">.<span class="keyword">class</span>)  </span></span><br><span class="line"><span class="class"><span class="title">public</span> <span class="title">AjaxResult</span> <span class="title">bindProcessAndBusiness</span>(<span class="title">String</span> <span class="title">approvalProcessBusiness</span>, <span class="title">String</span> <span class="title">deployId</span>, <span class="title">SysUser</span> <span class="title">sysUser</span>) </span>&#123;  </span><br><span class="line">    <span class="comment">// 检查当前额业务模型是否绑定  </span></span><br><span class="line">    SaBusinessBinding checkAlreadyBind = saBusinessBindingMapper.selectByBusinessName(approvalProcessBusiness);  </span><br><span class="line">    <span class="keyword">if</span> (Objects.nonNull(checkAlreadyBind)) &#123;  </span><br><span class="line">        <span class="keyword">return</span> AjaxResult.error(String.format(<span class="string">"Current Business %s Bound Approval Flow Model"</span>, checkAlreadyBind.getBusinessName()));  </span><br><span class="line">    &#125;  </span><br><span class="line">    SaBusinessBinding check = selectByProcessInstanceId(deployId);  </span><br><span class="line">    <span class="keyword">if</span> (Objects.nonNull(check) &amp;&amp; Objects.equals(check.getBusinessName(), approvalProcessBusiness)) &#123;  </span><br><span class="line">        String businessName = check.getBusinessName();  </span><br><span class="line">        <span class="keyword">return</span> AjaxResult.error(String.format(<span class="string">"Current Business %s Configured Approval Flow Model"</span>, businessName));  </span><br><span class="line">    &#125;  </span><br><span class="line">    Model model = repositoryService.createModelQuery().deploymentId(deployId).singleResult();  </span><br><span class="line">    <span class="keyword">if</span>(Objects.isNull(model))&#123;  </span><br><span class="line">        <span class="keyword">return</span> AjaxResult.error(<span class="string">"bindProcessAndBusiness model must be not null"</span>);  </span><br><span class="line">    &#125;  </span><br><span class="line">    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployId).singleResult();  </span><br><span class="line">    SaBusinessBinding saBusinessBinding = <span class="keyword">new</span> SaBusinessBinding();  </span><br><span class="line">    saBusinessBinding.setModelDefinitionMark(processDefinition.getKey());  </span><br><span class="line">    saBusinessBinding.setBusinessName(approvalProcessBusiness);  </span><br><span class="line">    saBusinessBinding.setCreateName(sysUser.getUserName());  </span><br><span class="line">    saBusinessBinding.setCreateTime(model.getCreateTime() != <span class="keyword">null</span> ? DateHelper.getString(model.getCreateTime(), DateHelper.yyyyMMdd_hhmmss) : DateHelper.getNowByNew(DateHelper.yyyyMMdd_hhmmss));  </span><br><span class="line">    saBusinessBinding.setCreateId(sysUser.getUserId());  </span><br><span class="line">    saBusinessBinding.setLastUpdateTime(model.getLastUpdateTime() != <span class="keyword">null</span> ? DateHelper.getString(model.getLastUpdateTime(), DateHelper.getNowByNew(DateHelper.yyyyMMdd_hhmmss)) : DateHelper.getNowByNew(DateHelper.yyyyMMdd_hhmmss));  </span><br><span class="line">    saBusinessBinding.setProcessStatus(<span class="string">"1"</span>);  </span><br><span class="line">    saBusinessBinding.setProcessInstanceId(deployId);  </span><br><span class="line">  </span><br><span class="line">    <span class="comment">// 根据deployId 删除再插入  </span></span><br><span class="line">    saBusinessBindingMapper.deleteByDeployId(deployId);  </span><br><span class="line">    saBusinessBindingMapper.insert(saBusinessBinding);  </span><br><span class="line">    <span class="keyword">return</span> AjaxResult.success();  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h2 id="12-2-启动流程实例"><a href="#12-2-启动流程实例" class="headerlink" title="12.2 启动流程实例"></a>12.2 启动流程实例</h2><p>构建流程增删改查之后，接下来将介绍如何构建和启动一个流程。</p>
<h3 id="12-2-1-什么是流程实例"><a href="#12-2-1-什么是流程实例" class="headerlink" title="12.2.1 什么是流程实例"></a>12.2.1 什么是流程实例</h3><p>流程实例（ProcessInstance）代表流程定义的执行实例。一个流程实例包括了所有的运行节点。我们可以利用这个对象来了解当前流程实例的进度等信息。</p>
<p>例如：我们部署了一个请求的工作流模型，定义了请求流程，现在要按照流程提交一个请求申请，就是启动流程实例。</p>
<p><img src="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/20230424104731.png" alt="image.png"></p>
<h3 id="12-2-2-启动实例和添加Businesskey（业务标识）"><a href="#12-2-2-启动实例和添加Businesskey（业务标识）" class="headerlink" title="12.2.2 启动实例和添加Businesskey（业务标识）"></a>12.2.2 启动实例和添加Businesskey（业务标识）</h3><p>流程定义部署在activiti后，就可以在系统中通过activiti去管理该流程的执行，执行流程表示流程的一次执行。启动流程实例时如果指定 businesskey，就会在 <strong>act_ru_execution</strong> 流程实例的执行表中存储businesskey。</p>
<p>Businesskey：业务标识，通常为业务表的主键，业务标识和流程实例一一对应。业务标识来源于业务系统。存储业务标识就是根据业务标识来关联查询业务系统的数据。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">    <span class="comment">/**     * 启动流程实例，添加businessKey     */</span>    </span><br><span class="line">    <span class="meta">@Test</span>    </span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">addBusinessKey</span><span class="params">()</span></span>&#123;</span><br><span class="line"><span class="comment">//        1、得到ProcessEngine</span></span><br><span class="line">        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();</span><br><span class="line"><span class="comment">//        2、得到RunTimeService</span></span><br><span class="line">        RuntimeService runtimeService = processEngine.getRuntimeService();</span><br><span class="line"><span class="comment">//        3、启动流程实例，同时还要指定业务标识businessKey</span></span><br><span class="line">        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(<span class="string">"myEvection"</span>,<span class="string">"1001"</span>);</span><br><span class="line"><span class="comment">//        4、输出processInstance相关属性</span></span><br><span class="line">        System.out.println(<span class="string">"业务id=="</span>+processInstance.getBusinessKey());</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<p>businessKey对应的就是部署流程表中的 <code>key_</code> 这个字段，name则对应我们流程模型的名称：</p>
<table>
<thead>
<tr>
<th>id_</th>
<th>name_</th>
<th>category_</th>
<th>key_</th>
<th>tenant_id_</th>
<th>deploy_time_</th>
<th>engine_version_</th>
</tr>
</thead>
<tbody><tr>
<td>22550</td>
<td>QAZX</td>
<td>QAZX</td>
<td>QAZX</td>
<td></td>
<td>########</td>
<td></td>
</tr>
<tr>
<td>27501</td>
<td>QAZX</td>
<td>QAZX</td>
<td>QAZX</td>
<td></td>
<td>########</td>
<td></td>
</tr>
<tr>
<td>112501</td>
<td>MerchantFreeze</td>
<td>MerchantFreeze</td>
<td>MerchantFreeze</td>
<td>########</td>
<td></td>
<td></td>
</tr>
<tr>
<td>135046</td>
<td>RiskRulesSetting</td>
<td>RiskRulesSetting</td>
<td>RiskRulesSetting</td>
<td>########</td>
<td></td>
<td></td>
</tr>
<tr>
<td>155047</td>
<td>MerchantFee</td>
<td>MerchantFee</td>
<td>MerchantFee</td>
<td>########</td>
<td></td>
<td></td>
</tr>
<tr>
<td>165001</td>
<td>regist</td>
<td>regist</td>
<td>regist</td>
<td></td>
<td>########</td>
<td></td>
</tr>
<tr>
<td>175044</td>
<td>IP</td>
<td>IP</td>
<td>IP</td>
<td></td>
<td>########</td>
<td></td>
</tr>
<tr>
<td>180047</td>
<td>regist</td>
<td>regist</td>
<td>regist</td>
<td></td>
<td>########</td>
<td></td>
</tr>
<tr>
<td>202595</td>
<td>MerchantOpenAccount</td>
<td>MerchantOpenAccount</td>
<td>MerchantOpenAccount</td>
<td>########</td>
<td></td>
<td></td>
</tr>
<tr>
<td>220004</td>
<td>MerchantVaRefund</td>
<td>MerchantVaRefund</td>
<td>MerchantVaRefund</td>
<td>########</td>
<td></td>
<td></td>
</tr>
<tr>
<td>225091</td>
<td>regist</td>
<td>regist</td>
<td>regist</td>
<td></td>
<td>########</td>
<td></td>
</tr>
</tbody></table>
<p>构建之后，从Activiti的<strong>act_ru_execution</strong>中存储业务标识，启动流程实例，操作如下数据库表：</p>
<figure class="highlight postgresql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">#流程实例执行表，记录当前流程实例的执行情况</span><br><span class="line"><span class="keyword">SELECT</span> * <span class="keyword">FROM</span> act_ru_execution;</span><br></pre></td></tr></table></figure>

<p>流程实例执行。如果当前只有一个分支，一个流程实例只有一条记录，且执行表的主键id和流程实例id相同，如果当前有多个分支正在运行则该执行表中有多条记录，存在执行表的主键和流程实例id不相同的记录。</p>
<p>不论当前有几个分支，总会有一条记录的执行表的主键和流程实例id相同。</p>
<h3 id="查询流程实例"><a href="#查询流程实例" class="headerlink" title="查询流程实例"></a>查询流程实例</h3><p>流程在运行过程中可以查询流程实例的状态，当前运行结点等信息。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Test</span>  </span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">queryProcessInstance</span><span class="params">()</span> </span>&#123;  </span><br><span class="line">   <span class="comment">// 流程定义key  </span></span><br><span class="line">   String processDefinitionKey = <span class="string">"evection"</span>;  </span><br><span class="line">   ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();  </span><br><span class="line">   <span class="comment">// 获取RunTimeService  </span></span><br><span class="line">   RuntimeService runtimeService = processEngine.getRuntimeService();  </span><br><span class="line">   List&lt;ProcessInstance&gt; list = runtimeService  </span><br><span class="line">         .createProcessInstanceQuery()  </span><br><span class="line">         .processDefinitionKey(processDefinitionKey)<span class="comment">//  </span></span><br><span class="line">         .list();  </span><br><span class="line">  </span><br><span class="line">   <span class="keyword">for</span> (ProcessInstance processInstance : list) &#123;  </span><br><span class="line">      System.out.println(<span class="string">"----------------------------"</span>);  </span><br><span class="line">      System.out.println(<span class="string">"流程实例id："</span>  </span><br><span class="line">            + processInstance.getProcessInstanceId());  </span><br><span class="line">      System.out.println(<span class="string">"所属流程定义id："</span>  </span><br><span class="line">            + processInstance.getProcessDefinitionId());  </span><br><span class="line">      System.out.println(<span class="string">"是否执行完成："</span> + processInstance.isEnded());  </span><br><span class="line">      System.out.println(<span class="string">"是否暂停："</span> + processInstance.isSuspended());  </span><br><span class="line">      System.out.println(<span class="string">"当前活动标识："</span> + processInstance.getActivityId());  </span><br><span class="line">   &#125;  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h4 id="关联BusinessKey"><a href="#关联BusinessKey" class="headerlink" title="关联BusinessKey"></a>关联BusinessKey</h4><p>在activiti实际应用时，查询流程实例列表可能要显示出业务系统的一些相关信息。在查询流程实例时，通过businessKey（业务标识 ）关联查询业务系统。通过下面的代码就可以获取activiti中所对应实例保存的业务Key。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">String businessKey = processInstance.getBusinessKey();</span><br></pre></td></tr></table></figure>

<blockquote>
<p>在activiti的<strong>act_ru_execution</strong>表，字段<strong>BUSINESS_KEY</strong>就是存放业务KEY的。</p>
</blockquote>
<h2 id="12-3-任务流转"><a href="#12-3-任务流转" class="headerlink" title="12.3 任务流转"></a>12.3 任务流转</h2><p>启动流程实例之后，接下来就是任务的增删改查，每一个Task对应了工作流中的活动，我们可以通过下面的方式查询任务负责人的待办任务：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 查询当前个人待执行的任务  </span></span><br><span class="line"><span class="meta">@Test</span>  </span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">findPersonalTaskList</span><span class="params">()</span> </span>&#123;  </span><br><span class="line">    <span class="comment">// 流程定义key  </span></span><br><span class="line">    String processDefinitionKey = <span class="string">"myEvection1"</span>;  </span><br><span class="line">    <span class="comment">// 任务负责人  </span></span><br><span class="line">    String assignee = <span class="string">"张三"</span>;  </span><br><span class="line">    <span class="comment">// 获取TaskService  </span></span><br><span class="line">    TaskService taskService = processEngine.getTaskService();  </span><br><span class="line">    List&lt;Task&gt; taskList = taskService.createTaskQuery()  </span><br><span class="line">            .processDefinitionKey(processDefinitionKey)  </span><br><span class="line">            .includeProcessVariables()  </span><br><span class="line">        	<span class="comment">// 任务负责人</span></span><br><span class="line">            .taskAssignee(assignee)  </span><br><span class="line">            .list();  </span><br><span class="line">    <span class="keyword">for</span> (Task task : taskList) &#123;  </span><br><span class="line">        System.out.println(<span class="string">"----------------------------"</span>);  </span><br><span class="line">        System.out.println(<span class="string">"流程实例id： "</span> + task.getProcessInstanceId());  </span><br><span class="line">        System.out.println(<span class="string">"任务id： "</span> + task.getId());  </span><br><span class="line">        System.out.println(<span class="string">"任务负责人： "</span> + task.getAssignee());  </span><br><span class="line">        System.out.println(<span class="string">"任务名称： "</span> + task.getName());  </span><br><span class="line">    &#125;  </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>我们可以通过组合查询条件，实现特定人员查询特定的业务内容。任务流转给下一个人需要先获取任务ID，然后调用taskService的complete方法完成当前审批人的代办任务。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**  </span></span><br><span class="line"><span class="comment">    * 完成任务，判断当前用户是否有权限  </span></span><br><span class="line"><span class="comment">    */</span>  </span><br><span class="line">   <span class="meta">@Test</span>  </span><br><span class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">completTask</span><span class="params">()</span> </span>&#123;  </span><br><span class="line">      <span class="comment">//任务id  </span></span><br><span class="line">      String taskId = <span class="string">"15005"</span>;  </span><br><span class="line"><span class="comment">//        任务负责人  </span></span><br><span class="line">      String assingee = <span class="string">"张三"</span>;  </span><br><span class="line">      <span class="comment">//获取processEngine  </span></span><br><span class="line">      ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();  </span><br><span class="line">      <span class="comment">// 创建TaskService  </span></span><br><span class="line">      TaskService taskService = processEngine.getTaskService();  </span><br><span class="line"><span class="comment">//        完成任务前，需要校验该负责人可以完成当前任务  </span></span><br><span class="line"><span class="comment">//        校验方法：  </span></span><br><span class="line"><span class="comment">//        根据任务id和任务负责人查询当前任务，如果查到该用户有权限，就完成  </span></span><br><span class="line">      Task task = taskService.createTaskQuery()  </span><br><span class="line">            .taskId(taskId)  </span><br><span class="line">            .taskAssignee(assingee)  </span><br><span class="line">            .singleResult();  </span><br><span class="line">      <span class="keyword">if</span>(task != <span class="keyword">null</span>)&#123;  </span><br><span class="line">         taskService.complete(taskId);  </span><br><span class="line">         System.out.println(<span class="string">"完成任务"</span>);  </span><br><span class="line">      &#125;  </span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>



<h2 id="12-4-完成任务"><a href="#12-4-完成任务" class="headerlink" title="12.4 完成任务"></a>12.4 完成任务</h2><p>注意：在实际应用中，完成任务前需要校验任务的负责人是否具有该任务的办理权限 。完成任务的模板代码和任务流转类似，但是需要额外判断当前节点是否为最后一个待办节点。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**  </span></span><br><span class="line"><span class="comment">    * 完成任务，判断当前用户是否有权限  </span></span><br><span class="line"><span class="comment">    */</span>  </span><br><span class="line">   <span class="meta">@Test</span>  </span><br><span class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">completTask</span><span class="params">()</span> </span>&#123;  </span><br><span class="line">      <span class="comment">//任务id  </span></span><br><span class="line">      String taskId = <span class="string">"15005"</span>;  </span><br><span class="line"><span class="comment">//        任务负责人  </span></span><br><span class="line">      String assingee = <span class="string">"张三"</span>;  </span><br><span class="line">      <span class="comment">//获取processEngine  </span></span><br><span class="line">      ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();  </span><br><span class="line">      <span class="comment">// 创建TaskService  </span></span><br><span class="line">      TaskService taskService = processEngine.getTaskService();  </span><br><span class="line"><span class="comment">//        完成任务前，需要校验该负责人可以完成当前任务  </span></span><br><span class="line"><span class="comment">//        校验方法：  </span></span><br><span class="line"><span class="comment">//        根据任务id和任务负责人查询当前任务，如果查到该用户有权限，就完成  </span></span><br><span class="line">      Task task = taskService.createTaskQuery()  </span><br><span class="line">            .taskId(taskId)  </span><br><span class="line">            .taskAssignee(assingee)  </span><br><span class="line">            .singleResult();  </span><br><span class="line">      <span class="keyword">if</span>(task != <span class="keyword">null</span>)&#123;  </span><br><span class="line">         taskService.complete(taskId);  </span><br><span class="line">         System.out.println(<span class="string">"完成任务"</span>);  </span><br><span class="line">      &#125;  </span><br><span class="line">   &#125;</span><br></pre></td></tr></table></figure>



<h3 id="12-4-1-如何知道当前节点是否为最后一个待办节点？"><a href="#12-4-1-如何知道当前节点是否为最后一个待办节点？" class="headerlink" title="12.4.1 如何知道当前节点是否为最后一个待办节点？"></a>12.4.1 如何知道当前节点是否为最后一个待办节点？</h3><p>具体可以阅读<code>com.sa.impl.utils.ActivityUtils#getNextNode(java.lang.String, java.lang.String, java.util.Map&lt;java.lang.String,java.lang.Object&gt;)</code>这一部分。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> List&lt;UserTask&gt; <span class="title">getNextNode</span><span class="params">(String procDefId, String taskDefKey, Map&lt;String, Object&gt; map)</span> </span>&#123;</span><br><span class="line">        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();</span><br><span class="line">        List&lt;UserTask&gt; userTasks = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">        <span class="comment">//获取BpmnModel对象</span></span><br><span class="line">        BpmnModel bpmnModel = processEngine.getRepositoryService().getBpmnModel(procDefId);</span><br><span class="line">        <span class="comment">//获取Process对象</span></span><br><span class="line">        Process process = bpmnModel.getProcesses().get(bpmnModel.getProcesses().size() - <span class="number">1</span>);</span><br><span class="line">        <span class="comment">//获取所有的FlowElement信息</span></span><br><span class="line">        Collection&lt;FlowElement&gt; flowElements = process.getFlowElements();</span><br><span class="line">        <span class="comment">//获取当前节点信息</span></span><br><span class="line">        FlowElement flowElement = getFlowElementById(taskDefKey, flowElements);</span><br><span class="line">        getNextNode(flowElements, flowElement, map, userTasks);</span><br><span class="line">        <span class="keyword">return</span> userTasks;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<p>整体思路是找到当前节点的所有连线，然后判断当前连线的下一个节点是否是一个“结束节点”，如果是则证明当前节点已经到达最后一步。</p>
<blockquote>
<p>PS：建议设计流程图仅仅为结束节点配一个前置节点和连线。</p>
</blockquote>
<h2 id="12-5-流程变量"><a href="#12-5-流程变量" class="headerlink" title="12.5 流程变量"></a>12.5 流程变量</h2><h3 id="12-5-1-什么是流程变量"><a href="#12-5-1-什么是流程变量" class="headerlink" title="12.5.1 什么是流程变量"></a>12.5.1 什么是流程变量</h3><p>流程变量在 activiti 中十分重要， 比如我们在流程变量当中维护一个“观察者角色列表”，将记录的所有可见角色到流程变量中存储，流程变量在流程控制中主要是控制流程流转的细节控制。</p>
<blockquote>
<p>注意：虽然流程变量中可以存储业务数据，也可以通过activiti的api查询流程变量实现查询业务数据，但是实际上不建议这样使用，因为业务数据查询由业务系统负责，activiti设置流程变量是为了流程执行需要而创建。</p>
</blockquote>
<h3 id="12-5-2-流程变量类型"><a href="#12-5-2-流程变量类型" class="headerlink" title="12.5.2 流程变量类型"></a>12.5.2 流程变量类型</h3><p>数据来源：<code>Table 10. Variable Types</code>。</p>
<p><span class="exturl" data-url="aHR0cHM6Ly93d3cuYWN0aXZpdGkub3JnLzUueC91c2VyZ3VpZGUvI2FwaVZhcmlhYmxlcw==" title="https://www.activiti.org/5.x/userguide/#apiVariables">https://www.activiti.org/5.x/userguide/#apiVariables<i class="fa fa-external-link"></i></span></p>
<table>
<thead>
<tr>
<th align="left">Type name</th>
<th align="left">Description</th>
</tr>
</thead>
<tbody><tr>
<td align="left">string</td>
<td align="left">Value is threaded as a <code>java.lang.String</code>. Raw JSON-text value is used when writing a variable.</td>
</tr>
<tr>
<td align="left">integer</td>
<td align="left">Value is threaded as a <code>java.lang.Integer</code>. When writing, JSON number value is used as base for conversion, falls back to JSON text.</td>
</tr>
<tr>
<td align="left">short</td>
<td align="left">Value is threaded as a <code>java.lang.Short</code>. When writing, JSON number value is used as base for conversion, falls back to JSON text.</td>
</tr>
<tr>
<td align="left">long</td>
<td align="left">Value is threaded as a <code>java.lang.Long</code>. When writing, JSON number value is used as base for conversion, falls back to JSON text.</td>
</tr>
<tr>
<td align="left">double</td>
<td align="left">Value is threaded as a <code>java.lang.Double</code>. When writing, JSON number value is used as base for conversion, falls back to JSON text.</td>
</tr>
<tr>
<td align="left">boolean</td>
<td align="left">Value is threaded as a <code>java.lang.Boolean</code>. When writing, JSON boolean value is used for conversion.</td>
</tr>
<tr>
<td align="left">date</td>
<td align="left">Value is treated as a <code>java.util.Date</code>. When writing, the JSON text will be converted using ISO-8601 date format.</td>
</tr>
<tr>
<td align="left">binary</td>
<td align="left">Binary variable, treated as an array of bytes. The <code>value</code> attribute is null, the <code>valueUrl</code> contains an URL pointing to the raw binary stream.</td>
</tr>
<tr>
<td align="left">serializable</td>
<td align="left">Serialized representation of a Serializable Java-object. As with the <code>binary</code> type, the <code>value</code> attribute is null, the <code>valueUrl</code> contains an URL pointing to the raw binary stream. All serializable variables (which are not of any of the above types) will be exposed as a variable of this type.</td>
</tr>
</tbody></table>
<h3 id="12-5-3-流程变量作用域"><a href="#12-5-3-流程变量作用域" class="headerlink" title="12.5.3 流程变量作用域"></a>12.5.3 流程变量作用域</h3><p>流程变量的作用域可以是一个流程实例(processInstance)，或一个任务(task)，或一个执行实例(execution)。</p>
<h4 id="globa变量"><a href="#globa变量" class="headerlink" title="globa变量"></a>globa变量</h4><p>流程变量的默认作用域是流程实例。当一个流程变量的作用域为流程实例时，可以称为 global 变量。</p>
<p>注意：</p>
<p>Global变量：userId（变量名）、zhangsan（变量值）</p>
<p>global 变量中变量名不允许重复，设置相同名称的变量，后设置的值会覆盖前设置的变量值。</p>
<h4 id="local变量"><a href="#local变量" class="headerlink" title="local变量"></a>local变量</h4><p>任务和执行实例仅仅是针对一个任务和一个执行实例范围，范围没有流程实例大， 称为 local 变量。</p>
<p>Local 变量由于在不同的任务或不同的执行实例中，作用域互不影响，变量名可以相同没有影响。Local 变量名也可以和 global 变量名相同，没有影响。</p>
<h3 id="12-5-4-流程变量的使用方法"><a href="#12-5-4-流程变量的使用方法" class="headerlink" title="12.5.4 流程变量的使用方法"></a>12.5.4 流程变量的使用方法</h3><p>可以在 assignee 处设置 UEL 表达式，表达式的值为任务的负责人，比如： ${assignee}， assignee 就是一个流程变量名称。</p>
<p>Activiti获取UEL表达式的值，即流程变量assignee的值 ，将assignee的值作为任务的负责人进行任务分配。</p>
<h3 id="12-5-5-在连线上使用UEL表达式"><a href="#12-5-5-在连线上使用UEL表达式" class="headerlink" title="12.5.5 在连线上使用UEL表达式"></a>12.5.5 在连线上使用UEL表达式</h3><p>可以在连线上设置UEL表达式，决定流程走向。比如：<code>${price&lt;10000}</code>。price就是一个流程变量名称，uel表达式结果类型为布尔类型。</p>
<p>如果UEL表达式是true，要决定 流程执行走向。</p>
<h3 id="12-5-6-启动实例设置流程变量"><a href="#12-5-6-启动实例设置流程变量" class="headerlink" title="12.5.6 启动实例设置流程变量"></a>12.5.6 启动实例设置流程变量</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">    <span class="comment">/**     * 启动流程实例,设置流程变量的值     */</span>    </span><br><span class="line">    <span class="meta">@Test</span>    </span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">startProcess</span><span class="params">()</span></span>&#123;</span><br><span class="line"><span class="comment">//        获取流程引擎</span></span><br><span class="line">        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();</span><br><span class="line"><span class="comment">//        获取RunTimeService</span></span><br><span class="line">        RuntimeService runtimeService = processEngine.getRuntimeService();</span><br><span class="line"><span class="comment">//        流程定义key</span></span><br><span class="line">        String key = <span class="string">"myEvection2"</span>;</span><br><span class="line"><span class="comment">//       创建变量集合</span></span><br><span class="line">        Map&lt;String, Object&gt; map = <span class="keyword">new</span> HashMap&lt;&gt;();</span><br><span class="line"><span class="comment">//        创建出差pojo对象</span></span><br><span class="line">        Evection evection = <span class="keyword">new</span> Evection();</span><br><span class="line"><span class="comment">//        设置出差天数</span></span><br><span class="line">        evection.setNum(<span class="number">2</span>d);</span><br><span class="line"><span class="comment">//      定义流程变量，把出差pojo对象放入map</span></span><br><span class="line">        map.put(<span class="string">"evection"</span>,evection);</span><br><span class="line"><span class="comment">//      设置assignee的取值，用户可以在界面上设置流程的执行</span></span><br><span class="line">        map.put(<span class="string">"assignee0"</span>,<span class="string">"张三"</span>);        </span><br><span class="line">        map.put(<span class="string">"assignee1"</span>,<span class="string">"李经理"</span>);        </span><br><span class="line">        map.put(<span class="string">"assignee2"</span>,<span class="string">"王总经理"</span>);        </span><br><span class="line">        map.put(<span class="string">"assignee3"</span>,<span class="string">"赵财务"</span>);</span><br><span class="line"><span class="comment">//        启动流程实例，并设置流程变量的值（把map传入）</span></span><br><span class="line">        ProcessInstance processInstance = runtimeService                .startProcessInstanceByKey(key, map);</span><br><span class="line"><span class="comment">//      输出</span></span><br><span class="line">        System.out.println(<span class="string">"流程实例名称="</span>+processInstance.getName());        </span><br><span class="line">        System.out.println(<span class="string">"流程定义id=="</span>+processInstance.getProcessDefinitionId());</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<p>需要注意，<strong>流程变量作用域是一个流程实例</strong>，流程变量使用Map存储，同一个流程实例设置变量map中key相同，后者覆盖前者。</p>
<h3 id="12-5-7-通过当前任务设置流程变量"><a href="#12-5-7-通过当前任务设置流程变量" class="headerlink" title="12.5.7 通过当前任务设置流程变量"></a>12.5.7 通过当前任务设置流程变量</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">String operateNow = DateHelper.getNowByNew(DateHelper.yyyyMMdd_hhmmss);</span><br><span class="line">HashMap&lt;String, Object&gt; variables = getProcessGlobalVariables(newCharge, operateNow, commit, user);</span><br><span class="line">ProcessInstance processInstance = runtimeService</span><br><span class="line">        .startProcessInstanceByKey(saBusinessBinding.getModelDefinitionMark(), saBusinessBinding.getBusinessName(), variables);</span><br><span class="line">Task autoTask = taskService.createTaskQuery()</span><br><span class="line">        .processDefinitionKey(saBusinessBinding.getModelDefinitionMark())</span><br><span class="line">        .processInstanceId(processInstance.getId())</span><br><span class="line">        .processInstanceBusinessKey(saBusinessBinding.getBusinessName()).singleResult();</span><br><span class="line">Comment comment = taskService.addComment(autoTask.getId(), processInstance.getProcessInstanceId(), (String) variables.get(BusinessBindVariables.COMMENT.getKey()));</span><br><span class="line">log.info(<span class="string">"Comment =&gt; &#123;&#125;"</span>, comment.getFullMessage());</span><br><span class="line"></span><br><span class="line">taskService</span><br><span class="line">        .complete(autoTask.getId(), variables);</span><br><span class="line">log.info(<span class="string">"&#123;&#125; commit Task &#123;&#125;"</span>, saBusinessBinding.getBusinessName(), autoTask.getId());</span><br></pre></td></tr></table></figure>

<p>关键代码在下面这一串：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">taskService</span><br><span class="line">        .complete(autoTask.getId(), variables);</span><br></pre></td></tr></table></figure>

<p>第二个参数可以传递流程变量，如果Key在当前流程实例已经存在就会覆盖。</p>
<h2 id="12-6-历史信息查询"><a href="#12-6-历史信息查询" class="headerlink" title="12.6 历史信息查询"></a>12.6 历史信息查询</h2><p>每个参与者在完成当前节点的“活动”之后，都会在历史信息中留下记录。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">HistoricProcessInstanceQuery condition = historyService.createHistoricProcessInstanceQuery();  </span><br><span class="line"><span class="keyword">if</span> (StringUtils.isNotEmpty(historyTaskRequestDto.getBussinessKey())) &#123;  </span><br><span class="line">    condition.processInstanceBusinessKey(CharSequenceUtil.trim(historyTaskRequestDto.getBussinessKey()));  </span><br><span class="line">&#125;  </span><br><span class="line"><span class="keyword">if</span> (StringUtils.isNotEmpty(historyTaskRequestDto.getName())) &#123;  </span><br><span class="line">    condition.processInstanceNameLikeIgnoreCase(CharSequenceUtil.trim(historyTaskRequestDto.getName()));  </span><br><span class="line">&#125;  </span><br><span class="line">List&lt;HistoricProcessInstance&gt; processList = condition.orderByProcessInstanceStartTime().desc()  </span><br><span class="line">        .list();</span><br></pre></td></tr></table></figure>

<p>我们可以通过 “ act_hi_* “开头的的表阅读所有有关审批流的历史记录和操作信息。</p>
<table>
<thead>
<tr>
<th>表名</th>
<th>表注释</th>
</tr>
</thead>
<tbody><tr>
<td>act_hi_actinst</td>
<td>历史节点表</td>
</tr>
<tr>
<td>act_hi_attachment</td>
<td>历史附件表</td>
</tr>
<tr>
<td>act_hi_comment</td>
<td>历史意见表</td>
</tr>
<tr>
<td>act_hi_detail</td>
<td>历史详情表，提供历史变量的查询</td>
</tr>
<tr>
<td>act_hi_identitylink</td>
<td>历史流程用户信息表</td>
</tr>
<tr>
<td>act_hi_procinst</td>
<td>历史流程实例表</td>
</tr>
<tr>
<td>act_hi_taskinst</td>
<td>历史任务实例表</td>
</tr>
<tr>
<td>act_hi_varinst</td>
<td>历史变量表</td>
</tr>
</tbody></table>
<blockquote>
</blockquote>
<h1 id="十三、学习参考资料汇总"><a href="#十三、学习参考资料汇总" class="headerlink" title="十三、学习参考资料汇总"></a>十三、学习参考资料汇总</h1><h2 id="13-1-技术选型部分"><a href="#13-1-技术选型部分" class="headerlink" title="13.1 技术选型部分"></a>13.1 技术选型部分</h2><h3 id="开源流程引擎哪个好，如何选型？-知乎-zhihu-com"><a href="#开源流程引擎哪个好，如何选型？-知乎-zhihu-com" class="headerlink" title="开源流程引擎哪个好，如何选型？ - 知乎 (zhihu.com)"></a><span class="exturl" data-url="aHR0cHM6Ly96aHVhbmxhbi56aGlodS5jb20vcC8zNjk3NjE4MzI=" title="https://zhuanlan.zhihu.com/p/369761832">开源流程引擎哪个好，如何选型？ - 知乎 (zhihu.com)<i class="fa fa-external-link"></i></span></h3><h3 id="常见的工作流方案对比"><a href="#常见的工作流方案对比" class="headerlink" title="常见的工作流方案对比"></a><span class="exturl" data-url="aHR0cHM6Ly9zZWdtZW50ZmF1bHQuY29tL2EvMTE5MDAwMDA0MTc2NjcyNQ==" title="https://segmentfault.com/a/1190000041766725">常见的工作流方案对比<i class="fa fa-external-link"></i></span></h3><h2 id="13-2-activiti6-0在线流程设计器"><a href="#13-2-activiti6-0在线流程设计器" class="headerlink" title="13.2 activiti6.0在线流程设计器"></a>13.2 activiti6.0在线流程设计器</h2><p>activiti6.0在线流程设计器，可以从代码中找到对应的WEB版本Activity流程设计器。</p>
<h3 id="juzhizhang-springboot2-activiti-design-activiti6-0在线流程设计器-github-com"><a href="#juzhizhang-springboot2-activiti-design-activiti6-0在线流程设计器-github-com" class="headerlink" title="juzhizhang/springboot2-activiti-design: activiti6.0在线流程设计器 (github.com)"></a><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2p1emhpemhhbmcvc3ByaW5nYm9vdDItYWN0aXZpdGktZGVzaWdu" title="https://github.com/juzhizhang/springboot2-activiti-design">juzhizhang/springboot2-activiti-design: activiti6.0在线流程设计器 (github.com)<i class="fa fa-external-link"></i></span></h3><h2 id="13-3-最简洁的入门DEMO教程"><a href="#13-3-最简洁的入门DEMO教程" class="headerlink" title="13.3 最简洁的入门DEMO教程"></a>13.3 最简洁的入门DEMO教程</h2><h3 id="21年最新版activiti7保姆教程"><a href="#21年最新版activiti7保姆教程" class="headerlink" title="# 21年最新版activiti7保姆教程"></a><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tLzI3MDUyMDAwNi9BY3Rpdml0eVN0dWR5" title="https://github.com/270520006/ActivityStudy"># 21年最新版activiti7保姆教程<i class="fa fa-external-link"></i></span></h3><blockquote>
<p>个人fork仓库： <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2xhenlUaW1lcy9BY3Rpdml0eVN0dWR5" title="https://github.com/lazyTimes/ActivityStudy">https://github.com/lazyTimes/ActivityStudy<i class="fa fa-external-link"></i></span></p>
</blockquote>
<h2 id="13-4-Activity使用讲义资料"><a href="#13-4-Activity使用讲义资料" class="headerlink" title="13.4 Activity使用讲义资料"></a>13.4 Activity使用讲义资料</h2><h3 id="Activiti工作流引擎进阶【收藏可做笔记系列】"><a href="#Activiti工作流引擎进阶【收藏可做笔记系列】" class="headerlink" title="# Activiti工作流引擎进阶【收藏可做笔记系列】"></a><span class="exturl" data-url="aHR0cHM6Ly9kZXZlbG9wZXIuYWxpeXVuLmNvbS9hcnRpY2xlLzk1MjIwNiNzbGlkZS0xMw==" title="https://developer.aliyun.com/article/952206#slide-13"># Activiti工作流引擎进阶【收藏可做笔记系列】<i class="fa fa-external-link"></i></span></h3><h2 id="13-5-工作流设计准则"><a href="#13-5-工作流设计准则" class="headerlink" title="13.5 工作流设计准则"></a>13.5 工作流设计准则</h2><h3 id="企业工作流设计原则及多项目整合开发注意事项-敏捷开发-Marilyn-InfoQ写作社区"><a href="#企业工作流设计原则及多项目整合开发注意事项-敏捷开发-Marilyn-InfoQ写作社区" class="headerlink" title="企业工作流设计原则及多项目整合开发注意事项_敏捷开发_Marilyn_InfoQ写作社区"></a><span class="exturl" data-url="aHR0cHM6Ly94aWUuaW5mb3EuY24vYXJ0aWNsZS9kOTA4MGVhYWMyOWQ5N2ZiNDRmYWIyZjI5" title="https://xie.infoq.cn/article/d9080eaac29d97fb44fab2f29">企业工作流设计原则及多项目整合开发注意事项_敏捷开发_Marilyn_InfoQ写作社区<i class="fa fa-external-link"></i></span></h3><h2 id="13-6-开源项目"><a href="#13-6-开源项目" class="headerlink" title="13.6 开源项目"></a>13.6 开源项目</h2><h3 id="推荐-2-个基于-SpringBoot-的工作流项目，有用！"><a href="#推荐-2-个基于-SpringBoot-的工作流项目，有用！" class="headerlink" title="# 推荐 2 个基于 SpringBoot 的工作流项目，有用！"></a><span class="exturl" data-url="aHR0cHM6Ly9qdWVqaW4uY24vcG9zdC83MDY5NTQ1Mjg3MDA1NTAzNDk1" title="https://juejin.cn/post/7069545287005503495"># 推荐 2 个基于 SpringBoot 的工作流项目，有用！<i class="fa fa-external-link"></i></span></h3><h3 id="RuoYi-activiti"><a href="#RuoYi-activiti" class="headerlink" title="# RuoYi-activiti"></a><span class="exturl" data-url="aHR0cHM6Ly9naXRlZS5jb20vc2hlbnpoYW53YW5nL1J1b1lpLWFjdGl2aXRp" title="https://gitee.com/shenzhanwang/RuoYi-activiti"># RuoYi-activiti<i class="fa fa-external-link"></i></span></h3><h2 id="13-7-视频教程"><a href="#13-7-视频教程" class="headerlink" title="13.7 视频教程"></a>13.7 视频教程</h2><h3 id="activiti-5-流程初体验"><a href="#activiti-5-流程初体验" class="headerlink" title="activiti-5-流程初体验"></a><span class="exturl" data-url="aHR0cHM6Ly93d3cuYmlsaWJpbGkuY29tL3ZpZGVvL0JWMWJvNHkxRDduMz9wPTUmdmRfc291cmNlPTgyYjZmMjRmYzY5OWM0MDBjMDk3N2M2M2Q3YjM3ZjY0" title="https://www.bilibili.com/video/BV1bo4y1D7n3?p=5&vd_source=82b6f24fc699c400c0977c63d7b37f64">activiti-5-流程初体验<i class="fa fa-external-link"></i></span></h3><blockquote>
<p>对应笔记：<span class="exturl" data-url="aHR0cHM6Ly9kZXZlbG9wZXIuYWxpeXVuLmNvbS9hcnRpY2xlLzk1MjIwNiNzbGlkZS0xMw==" title="https://developer.aliyun.com/article/952206#slide-13"># Activiti工作流引擎进阶【收藏可做笔记系列】<i class="fa fa-external-link"></i></span></p>
</blockquote>
<h2 id="13-8-其他教程"><a href="#13-8-其他教程" class="headerlink" title="13.8 其他教程"></a>13.8 其他教程</h2><h3 id="SpringBoot系列——Activiti7工作流引擎"><a href="#SpringBoot系列——Activiti7工作流引擎" class="headerlink" title="SpringBoot系列——Activiti7工作流引擎 "></a><span class="exturl" data-url="aHR0cHM6Ly93d3cuY25ibG9ncy5jb20vaHVhbnppLXFjaC9wLzE0NzU4ODU4Lmh0bWw=" title="https://www.cnblogs.com/huanzi-qch/p/14758858.html">SpringBoot系列——Activiti7工作流引擎 <i class="fa fa-external-link"></i></span></h3><h2 id="13-9-官方快速开始"><a href="#13-9-官方快速开始" class="headerlink" title="13.9 官方快速开始"></a>13.9 官方快速开始</h2><h3 id="Quick-Start-Guide"><a href="#Quick-Start-Guide" class="headerlink" title="# Quick Start Guide"></a><span class="exturl" data-url="aHR0cHM6Ly93d3cuYWN0aXZpdGkub3JnL3F1aWNrLXN0YXJ0" title="https://www.activiti.org/quick-start"># Quick Start Guide<i class="fa fa-external-link"></i></span></h3><h3 id="Activiti-User-Guide"><a href="#Activiti-User-Guide" class="headerlink" title="# Activiti User Guide"></a><span class="exturl" data-url="aHR0cHM6Ly93d3cuYWN0aXZpdGkub3JnLzUueC91c2VyZ3VpZGUv" title="https://www.activiti.org/5.x/userguide/"># Activiti User Guide<i class="fa fa-external-link"></i></span></h3><h2 id="13-10-参考PPT"><a href="#13-10-参考PPT" class="headerlink" title="13.10 参考PPT"></a>13.10 参考PPT</h2><p><span class="exturl" data-url="aHR0cHM6Ly9zbGlkZXBsYXllci5jb20vc2xpZGUvMTA1MjcwMzkv" title="https://slideplayer.com/slide/10527039/">https://slideplayer.com/slide/10527039/<i class="fa fa-external-link"></i></span></p>
<h2 id="13-11-Camunda"><a href="#13-11-Camunda" class="headerlink" title="13.11 Camunda"></a>13.11 Camunda</h2><p><span class="exturl" data-url="aHR0cHM6Ly9zZWdtZW50ZmF1bHQuY29tL2EvMTE5MDAwMDA0MTc2NjcyNQ==" title="https://segmentfault.com/a/1190000041766725">javascript - 常见的工作流方案对比 - 技术博客，人生所思 - SegmentFault 思否<i class="fa fa-external-link"></i></span></p>
<h1 id="十四、总结"><a href="#十四、总结" class="headerlink" title="十四、总结"></a>十四、总结</h1><ol>
<li>工作流实践优于理论，概念比较复杂，但是有很多十分成熟并且稳定的框架。</li>
<li>本着“最少知识”的原则，工作流的业务编码应该尽可能的简化和易于理解。</li>
<li>流程图规划非常重要，每一个流程设计出错都有可能实际运行的时候无法进行。</li>
<li>工作流技术十分稳定，更新迭代非常缓慢。</li>
<li><strong>Talk is cheap. Show me your code</strong>。不要害怕未知领域。</li>
</ol>
<h1 id="十五、写在最后"><a href="#十五、写在最后" class="headerlink" title="十五、写在最后"></a>十五、写在最后</h1><p>授人以鱼不如授人以渔，本次内容是在用工作流实现实际生产业务之后补充整理而成，个人认为作为从零了解工作流入门开发的一个比较好的教程和参考，希望通过本次内容让读者可以了解到如何在碰到业务需要工作流的时候如何快速学习和上手开发。</p>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kity@2.0.4/dist/kity.min.js"></script><script type="text/javascript" src="https://cdn.jsdelivr.net/npm/kityminder-core@1.4.50/dist/kityminder.core.min.js"></script><script defer="true" type="text/javascript" src="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.js"></script><link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/hexo-simple-mindmap@0.2.0/dist/mindmap.min.css">
    </div>

    
    
    
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>lazytime
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://whitestore.top/2023/07/09/activitystudy/" title="【Activity】从零开始到掌握工作流开发业务代码">https://whitestore.top/2023/07/09/activitystudy/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <span class="exturl" data-url="aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLzQuMC96aC1DTg=="><i class="fa fa-fw fa-creative-commons"></i>BY-NC</span> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Activity/" rel="tag"># Activity</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2023/06/16/differencebetween/" rel="prev" title="【Java】What s the difference between SoftReference and WeakReference in Java">
      <i class="fa fa-chevron-left"></i> 【Java】What s the difference between SoftReference and WeakReference in Java
    </a></div>
      <div class="post-nav-item">
    <a href="/2023/07/09/netty_live/" rel="next" title="《跟闪电侠学Netty》阅读笔记 - ChannelHandler 生命周期">
      《跟闪电侠学Netty》阅读笔记 - ChannelHandler 生命周期 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#【Activity】从零开始到掌握工作流开发业务代码"><span class="nav-number">1.</span> <span class="nav-text">【Activity】从零开始到掌握工作流开发业务代码</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#目录"><span class="nav-number">2.</span> <span class="nav-text">目录</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#引言"><span class="nav-number">3.</span> <span class="nav-text">引言</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#一、工作流术语定义"><span class="nav-number">4.</span> <span class="nav-text">一、工作流术语定义</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-1-基本定义"><span class="nav-number">4.1.</span> <span class="nav-text">1.1 基本定义</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-2-相关术语"><span class="nav-number">4.2.</span> <span class="nav-text">1.2 相关术语</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-3-为什么被叫做流？"><span class="nav-number">4.3.</span> <span class="nav-text">1.3 为什么被叫做流？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-4-通俗理解"><span class="nav-number">4.4.</span> <span class="nav-text">1.4 通俗理解</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-5-生命周期"><span class="nav-number">4.5.</span> <span class="nav-text">1.5 生命周期</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#二、为什么需要工作流"><span class="nav-number">5.</span> <span class="nav-text">二、为什么需要工作流</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#2-1-工作流管理系统优势"><span class="nav-number">5.1.</span> <span class="nav-text">2.1 工作流管理系统优势</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-2-业务可视化"><span class="nav-number">5.2.</span> <span class="nav-text">2.2 业务可视化</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-3-业务可编排"><span class="nav-number">5.3.</span> <span class="nav-text">2.3 业务可编排</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-4-自动重试"><span class="nav-number">5.4.</span> <span class="nav-text">2.4 自动重试</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#三、常见开源工作流的对比（国外报告）"><span class="nav-number">6.</span> <span class="nav-text">三、常见开源工作流的对比（国外报告）</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#四、工作流使用场景"><span class="nav-number">7.</span> <span class="nav-text">四、工作流使用场景</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#4-1-领域业务高复杂度"><span class="nav-number">7.1.</span> <span class="nav-text">4.1 领域业务高复杂度</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-2-多节点、长链路"><span class="nav-number">7.2.</span> <span class="nav-text">4.2 多节点、长链路</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-3-状态持久化和自动重试"><span class="nav-number">7.3.</span> <span class="nav-text">4.3 状态持久化和自动重试</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#五、工作流分类"><span class="nav-number">8.</span> <span class="nav-text">五、工作流分类</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#5-1-内存工作流"><span class="nav-number">8.1.</span> <span class="nav-text">5.1 内存工作流</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-2-状态机工作流"><span class="nav-number">8.2.</span> <span class="nav-text">5.2 状态机工作流</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-3-人工工作流"><span class="nav-number">8.3.</span> <span class="nav-text">5.3 人工工作流</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#六、工作流设计准则"><span class="nav-number">9.</span> <span class="nav-text">六、工作流设计准则</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#6-1-工作流设计准则"><span class="nav-number">9.1.</span> <span class="nav-text">6.1 工作流设计准则</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#6-1-1-角色"><span class="nav-number">9.1.1.</span> <span class="nav-text">6.1.1 角色</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-1-2-内容：提炼最小集合"><span class="nav-number">9.1.2.</span> <span class="nav-text">6.1.2 内容：提炼最小集合</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-1-3-根据业务设计流程"><span class="nav-number">9.1.3.</span> <span class="nav-text">6.1.3 根据业务设计流程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-1-4-审批动作确定"><span class="nav-number">9.1.4.</span> <span class="nav-text">6.1.4 审批动作确定</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-1-5-权限"><span class="nav-number">9.1.5.</span> <span class="nav-text">6.1.5 权限</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-1-6-配置和扩展性"><span class="nav-number">9.1.6.</span> <span class="nav-text">6.1.6 配置和扩展性</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#6-1-7-效率"><span class="nav-number">9.1.7.</span> <span class="nav-text">6.1.7 效率</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-2-流程编排"><span class="nav-number">9.2.</span> <span class="nav-text">6.2 流程编排</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-3-异常处理"><span class="nav-number">9.3.</span> <span class="nav-text">6.3 异常处理</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-4-工作流问题"><span class="nav-number">9.4.</span> <span class="nav-text">6.4 工作流问题</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-5-不适用场景"><span class="nav-number">9.5.</span> <span class="nav-text">6.5 不适用场景</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-6-工作流业务特点"><span class="nav-number">9.6.</span> <span class="nav-text">6.6 工作流业务特点</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-7-工作流思想"><span class="nav-number">9.7.</span> <span class="nav-text">6.7 工作流思想</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#七、工作流技术选型"><span class="nav-number">10.</span> <span class="nav-text">七、工作流技术选型</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#7-1-Osworkflow"><span class="nav-number">10.1.</span> <span class="nav-text">7.1 Osworkflow</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-2-JBPM"><span class="nav-number">10.2.</span> <span class="nav-text">7.2 JBPM</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-3-Activiti"><span class="nav-number">10.3.</span> <span class="nav-text">7.3 Activiti</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-4-Flowable"><span class="nav-number">10.4.</span> <span class="nav-text">7.4 Flowable</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-5-Camunda"><span class="nav-number">10.5.</span> <span class="nav-text">7.5 Camunda</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-6-Easy-flow"><span class="nav-number">10.6.</span> <span class="nav-text">7.6 Easy-flow</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-7-compileflow"><span class="nav-number">10.7.</span> <span class="nav-text">7.7 compileflow</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-8-推荐组合"><span class="nav-number">10.8.</span> <span class="nav-text">7.8 推荐组合</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#八、流程设计器选型"><span class="nav-number">11.</span> <span class="nav-text">八、流程设计器选型</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#8-1-bpmn-js"><span class="nav-number">11.0.1.</span> <span class="nav-text">8.1 bpmn-js</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-2-mxGraph"><span class="nav-number">11.0.2.</span> <span class="nav-text">8.2 mxGraph</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8-3-Activiti-Modeler"><span class="nav-number">11.1.</span> <span class="nav-text">8.3 Activiti-Modeler</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8-4-Flowable-Modeler"><span class="nav-number">11.2.</span> <span class="nav-text">8.4 Flowable-Modeler</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8-5-IDEA-Activiti-BPMN-插件"><span class="nav-number">11.3.</span> <span class="nav-text">8.5 IDEA Activiti BPMN 插件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8-6-logicFlow"><span class="nav-number">11.4.</span> <span class="nav-text">8.6 logicFlow</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#九、Activity-详解"><span class="nav-number">12.</span> <span class="nav-text">九、Activity 详解</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#9-1-为什么要使用-Activity？"><span class="nav-number">12.1.</span> <span class="nav-text">9.1 为什么要使用 Activity？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#9-2-Activity-特点"><span class="nav-number">12.2.</span> <span class="nav-text">9.2 Activity 特点</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#9-3-Activiti-应用"><span class="nav-number">12.3.</span> <span class="nav-text">9.3 Activiti 应用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#9-4-Activiti框架与组件"><span class="nav-number">12.4.</span> <span class="nav-text">9.4 Activiti框架与组件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#9-6-Activity-工作流要点"><span class="nav-number">12.5.</span> <span class="nav-text">9.6 Activity 工作流要点</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#9-6-1-Idea插件（学习）"><span class="nav-number">12.5.1.</span> <span class="nav-text">9.6.1 Idea插件（学习）</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#9-6-2-常用-Service"><span class="nav-number">12.5.2.</span> <span class="nav-text">9.6.2 常用 Service</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#9-6-3-ProcessEngine对象"><span class="nav-number">12.5.3.</span> <span class="nav-text">9.6.3 ProcessEngine对象</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#9-6-4-安全管理"><span class="nav-number">12.5.4.</span> <span class="nav-text">9.6.4 安全管理</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#9-6-5-配置文件-activiti-cfg-xml"><span class="nav-number">12.5.5.</span> <span class="nav-text">9.6.5 配置文件 activiti.cfg.xml</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#9-6-6-application-yml-配置文件"><span class="nav-number">12.5.6.</span> <span class="nav-text">9.6.6 application.yml 配置文件</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#9-7-表结构"><span class="nav-number">12.6.</span> <span class="nav-text">9.7 表结构</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#9-7-1-5-种数据库表"><span class="nav-number">12.6.1.</span> <span class="nav-text">9.7.1 5 种数据库表</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#9-7-2-所有数据表简介"><span class="nav-number">12.6.2.</span> <span class="nav-text">9.7.2 所有数据表简介</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#全局通用数据（ACT-GE-）"><span class="nav-number">12.6.2.1.</span> <span class="nav-text">全局通用数据（ACT_GE_*）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#静态信息表（ACT-RE-）"><span class="nav-number">12.6.2.2.</span> <span class="nav-text">静态信息表（ACT_RE_*）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#运行数据（ACT-RU-）"><span class="nav-number">12.6.2.3.</span> <span class="nav-text">运行数据（ACT_RU_*）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#历史数据（ACT-HI-）"><span class="nav-number">12.6.2.4.</span> <span class="nav-text">历史数据（ACT_HI_*）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#其它表"><span class="nav-number">12.6.2.5.</span> <span class="nav-text">其它表</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#十、项目集成-Activity"><span class="nav-number">13.</span> <span class="nav-text">十、项目集成 Activity</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#10-1-版本选择"><span class="nav-number">13.0.1.</span> <span class="nav-text">10.1 版本选择</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#10-2-集成-Activity-web-编辑器"><span class="nav-number">13.1.</span> <span class="nav-text">10.2 集成 Activity web 编辑器</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#10-3-提供Activity-web-编辑器必要API接口"><span class="nav-number">13.2.</span> <span class="nav-text">10.3  提供Activity web 编辑器必要API接口</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#10-3-1-editor-跳转集成"><span class="nav-number">13.2.1.</span> <span class="nav-text">10.3.1 editor 跳转集成</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#10-3-2-sterncliset-接口提供"><span class="nav-number">13.2.2.</span> <span class="nav-text">10.3.2 sterncliset 接口提供</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#10-3-3-加载指定模型数据"><span class="nav-number">13.2.3.</span> <span class="nav-text">10.3.3 加载指定模型数据</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#10-3-4-保存模型接口"><span class="nav-number">13.2.4.</span> <span class="nav-text">10.3.4 保存模型接口</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#10-3-5-关闭页面"><span class="nav-number">13.2.5.</span> <span class="nav-text">10.3.5 关闭页面</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#10-3-6-去除Activity-logo"><span class="nav-number">13.2.6.</span> <span class="nav-text">10.3.6 去除Activity logo</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#10-3-7-不必要组件流程组件"><span class="nav-number">13.2.7.</span> <span class="nav-text">10.3.7 不必要组件流程组件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#10-3-8-隐藏不必要的底部编辑窗口"><span class="nav-number">13.2.8.</span> <span class="nav-text">10.3.8 隐藏不必要的底部编辑窗口</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#10-3-9-分配负责人转为下拉框"><span class="nav-number">13.2.9.</span> <span class="nav-text">10.3.9 分配负责人转为下拉框</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#10-3-10-最终检查"><span class="nav-number">13.2.10.</span> <span class="nav-text">10.3.10 最终检查</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#10-4-可能遇到的问题"><span class="nav-number">13.3.</span> <span class="nav-text">10.4 可能遇到的问题</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#10-4-1-Factory-method-‘springProcessEngineConfiguration’-threw-exception-nested-exception-is-java-io-FileNotFoundException-class-path-resource-processes-cannot-be-resolved-to-URL-because-it-does-not-exist"><span class="nav-number">13.3.1.</span> <span class="nav-text">10.4.1 Factory method ‘springProcessEngineConfiguration’ threw exception; nested exception is java.io.FileNotFoundException: class path resource [processes&#x2F;] cannot be resolved to URL because it does not exist</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#10-4-2-application-yml-配置"><span class="nav-number">13.3.2.</span> <span class="nav-text">10.4.2 application.yml 配置</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#10-4-3-java-lang-IllegalArgumentException-Could-not-find-class-org-springframework-boot-autoconfigure-security-SecurityAutoConfiguration"><span class="nav-number">13.3.3.</span> <span class="nav-text">10.4.3 java.lang.IllegalArgumentException: Could not find class [org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration]</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#10-4-4-Failed-to-process-import-candidates-for-configuration-class-com-sa-SaAdminImplApplication-nested-exception-is-java-io-FileNotFoundException-class-path-resource-org-springframework-security-config-annotation-authentication-configurers-GlobalAuthenticationConfigurerAdapter-class-cannot-be-opened-because-it-does-not-exist"><span class="nav-number">13.3.4.</span> <span class="nav-text">10.4.4 Failed to process import candidates for configuration class [com.sa.SaAdminImplApplication]; nested exception is java.io.FileNotFoundException: class path resource [org&#x2F;springframework&#x2F;security&#x2F;config&#x2F;annotation&#x2F;authentication&#x2F;configurers&#x2F;GlobalAuthenticationConfigurerAdapter.class] cannot be opened because it does not exist</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#10-4-5-可视化编辑器的页面白板问题处理"><span class="nav-number">13.3.5.</span> <span class="nav-text">10.4.5 可视化编辑器的页面白板问题处理</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#10-4-6-补充：集成到实际项目的注意事项"><span class="nav-number">13.3.6.</span> <span class="nav-text">10.4.6 补充：集成到实际项目的注意事项</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#十一、Activity-设计流程图（各种组件，如连线、用户任务、网关）"><span class="nav-number">14.</span> <span class="nav-text">十一、Activity 设计流程图（各种组件，如连线、用户任务、网关）</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#11-1-各种组件"><span class="nav-number">14.1.</span> <span class="nav-text">11.1 各种组件</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#11-2-0-主界面"><span class="nav-number">14.1.1.</span> <span class="nav-text">11.2.0 主界面</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#11-2-1-Start-Events"><span class="nav-number">14.1.2.</span> <span class="nav-text">11.2.1 Start Events</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#11-2-2-EndEvents"><span class="nav-number">14.1.3.</span> <span class="nav-text">11.2.2 EndEvents</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#11-2-3-插曲：最简单的工作流"><span class="nav-number">14.1.4.</span> <span class="nav-text">11.2.3 插曲：最简单的工作流</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#11-2-4-User-Task"><span class="nav-number">14.1.5.</span> <span class="nav-text">11.2.4 User Task</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#11-2-连线"><span class="nav-number">14.2.</span> <span class="nav-text">11.2 连线</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#11-3-用户任务"><span class="nav-number">14.3.</span> <span class="nav-text">11.3 用户任务</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#11-4-网关"><span class="nav-number">14.4.</span> <span class="nav-text">11.4 网关</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#11-4-1-什么是排他网关"><span class="nav-number">14.4.1.</span> <span class="nav-text">11.4.1 什么是排他网关?</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#为什么要用排他网关？"><span class="nav-number">14.4.1.1.</span> <span class="nav-text">为什么要用排他网关？</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#11-4-2-并行网关ParallelGateway"><span class="nav-number">14.4.2.</span> <span class="nav-text">11.4.2 并行网关ParallelGateway</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#11-4-3-什么是包含网关"><span class="nav-number">14.4.3.</span> <span class="nav-text">11.4.3 什么是包含网关</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#11-4-4-事件网关-EventGateway"><span class="nav-number">14.4.4.</span> <span class="nav-text">11.4.4 事件网关 EventGateway</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#十二、如何使用-Activity-进行开发"><span class="nav-number">15.</span> <span class="nav-text">十二、如何使用 Activity 进行开发</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#12-1-流程定义增删改查"><span class="nav-number">15.1.</span> <span class="nav-text">12.1 流程定义增删改查</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#12-1-1-添加新模型代码"><span class="nav-number">15.1.1.</span> <span class="nav-text">12.1.1 添加新模型代码</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#12-1-2-查询所有流程模型"><span class="nav-number">15.1.2.</span> <span class="nav-text">12.1.2 查询所有流程模型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#12-1-3-分页查询流程模型"><span class="nav-number">15.1.3.</span> <span class="nav-text">12.1.3 分页查询流程模型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#12-1-4-删除流程模型"><span class="nav-number">15.1.4.</span> <span class="nav-text">12.1.4 删除流程模型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#12-1-5-导出模型"><span class="nav-number">15.1.5.</span> <span class="nav-text">12.1.5 导出模型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#12-1-6-部署流程"><span class="nav-number">15.1.6.</span> <span class="nav-text">12.1.6 部署流程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#12-1-7-业务绑定"><span class="nav-number">15.1.7.</span> <span class="nav-text">12.1.7 业务绑定</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#12-2-启动流程实例"><span class="nav-number">15.2.</span> <span class="nav-text">12.2 启动流程实例</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#12-2-1-什么是流程实例"><span class="nav-number">15.2.1.</span> <span class="nav-text">12.2.1 什么是流程实例</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#12-2-2-启动实例和添加Businesskey（业务标识）"><span class="nav-number">15.2.2.</span> <span class="nav-text">12.2.2 启动实例和添加Businesskey（业务标识）</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#查询流程实例"><span class="nav-number">15.2.3.</span> <span class="nav-text">查询流程实例</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#关联BusinessKey"><span class="nav-number">15.2.3.1.</span> <span class="nav-text">关联BusinessKey</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#12-3-任务流转"><span class="nav-number">15.3.</span> <span class="nav-text">12.3 任务流转</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#12-4-完成任务"><span class="nav-number">15.4.</span> <span class="nav-text">12.4 完成任务</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#12-4-1-如何知道当前节点是否为最后一个待办节点？"><span class="nav-number">15.4.1.</span> <span class="nav-text">12.4.1 如何知道当前节点是否为最后一个待办节点？</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#12-5-流程变量"><span class="nav-number">15.5.</span> <span class="nav-text">12.5 流程变量</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#12-5-1-什么是流程变量"><span class="nav-number">15.5.1.</span> <span class="nav-text">12.5.1 什么是流程变量</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#12-5-2-流程变量类型"><span class="nav-number">15.5.2.</span> <span class="nav-text">12.5.2 流程变量类型</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#12-5-3-流程变量作用域"><span class="nav-number">15.5.3.</span> <span class="nav-text">12.5.3 流程变量作用域</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#globa变量"><span class="nav-number">15.5.3.1.</span> <span class="nav-text">globa变量</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#local变量"><span class="nav-number">15.5.3.2.</span> <span class="nav-text">local变量</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#12-5-4-流程变量的使用方法"><span class="nav-number">15.5.4.</span> <span class="nav-text">12.5.4 流程变量的使用方法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#12-5-5-在连线上使用UEL表达式"><span class="nav-number">15.5.5.</span> <span class="nav-text">12.5.5 在连线上使用UEL表达式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#12-5-6-启动实例设置流程变量"><span class="nav-number">15.5.6.</span> <span class="nav-text">12.5.6 启动实例设置流程变量</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#12-5-7-通过当前任务设置流程变量"><span class="nav-number">15.5.7.</span> <span class="nav-text">12.5.7 通过当前任务设置流程变量</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#12-6-历史信息查询"><span class="nav-number">15.6.</span> <span class="nav-text">12.6 历史信息查询</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#十三、学习参考资料汇总"><span class="nav-number">16.</span> <span class="nav-text">十三、学习参考资料汇总</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#13-1-技术选型部分"><span class="nav-number">16.1.</span> <span class="nav-text">13.1 技术选型部分</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#开源流程引擎哪个好，如何选型？-知乎-zhihu-com"><span class="nav-number">16.1.1.</span> <span class="nav-text">开源流程引擎哪个好，如何选型？ - 知乎 (zhihu.com)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#常见的工作流方案对比"><span class="nav-number">16.1.2.</span> <span class="nav-text">常见的工作流方案对比</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#13-2-activiti6-0在线流程设计器"><span class="nav-number">16.2.</span> <span class="nav-text">13.2 activiti6.0在线流程设计器</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#juzhizhang-springboot2-activiti-design-activiti6-0在线流程设计器-github-com"><span class="nav-number">16.2.1.</span> <span class="nav-text">juzhizhang&#x2F;springboot2-activiti-design: activiti6.0在线流程设计器 (github.com)</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#13-3-最简洁的入门DEMO教程"><span class="nav-number">16.3.</span> <span class="nav-text">13.3 最简洁的入门DEMO教程</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#21年最新版activiti7保姆教程"><span class="nav-number">16.3.1.</span> <span class="nav-text"># 21年最新版activiti7保姆教程</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#13-4-Activity使用讲义资料"><span class="nav-number">16.4.</span> <span class="nav-text">13.4 Activity使用讲义资料</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Activiti工作流引擎进阶【收藏可做笔记系列】"><span class="nav-number">16.4.1.</span> <span class="nav-text"># Activiti工作流引擎进阶【收藏可做笔记系列】</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#13-5-工作流设计准则"><span class="nav-number">16.5.</span> <span class="nav-text">13.5 工作流设计准则</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#企业工作流设计原则及多项目整合开发注意事项-敏捷开发-Marilyn-InfoQ写作社区"><span class="nav-number">16.5.1.</span> <span class="nav-text">企业工作流设计原则及多项目整合开发注意事项_敏捷开发_Marilyn_InfoQ写作社区</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#13-6-开源项目"><span class="nav-number">16.6.</span> <span class="nav-text">13.6 开源项目</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#推荐-2-个基于-SpringBoot-的工作流项目，有用！"><span class="nav-number">16.6.1.</span> <span class="nav-text"># 推荐 2 个基于 SpringBoot 的工作流项目，有用！</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#RuoYi-activiti"><span class="nav-number">16.6.2.</span> <span class="nav-text"># RuoYi-activiti</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#13-7-视频教程"><span class="nav-number">16.7.</span> <span class="nav-text">13.7 视频教程</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#activiti-5-流程初体验"><span class="nav-number">16.7.1.</span> <span class="nav-text">activiti-5-流程初体验</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#13-8-其他教程"><span class="nav-number">16.8.</span> <span class="nav-text">13.8 其他教程</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#SpringBoot系列——Activiti7工作流引擎"><span class="nav-number">16.8.1.</span> <span class="nav-text">SpringBoot系列——Activiti7工作流引擎 </span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#13-9-官方快速开始"><span class="nav-number">16.9.</span> <span class="nav-text">13.9 官方快速开始</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#Quick-Start-Guide"><span class="nav-number">16.9.1.</span> <span class="nav-text"># Quick Start Guide</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Activiti-User-Guide"><span class="nav-number">16.9.2.</span> <span class="nav-text"># Activiti User Guide</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#13-10-参考PPT"><span class="nav-number">16.10.</span> <span class="nav-text">13.10 参考PPT</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#13-11-Camunda"><span class="nav-number">16.11.</span> <span class="nav-text">13.11 Camunda</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#十四、总结"><span class="nav-number">17.</span> <span class="nav-text">十四、总结</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#十五、写在最后"><span class="nav-number">18.</span> <span class="nav-text">十五、写在最后</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">阿东</p>
  <div class="site-description" itemprop="description">随遇而安</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">239</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">36</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">37</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2xhenlUaW1lcw==" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;lazyTimes"><i class="fa fa-fw fa-github"></i>GitHub</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="bWFpbHRvOjEwOTc0ODM1MDhAcXEuY29t" title="E-Mail → mailto:1097483508@qq.com"><i class="fa fa-fw fa-envelope"></i>E-Mail</span>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly93d3cuNTJwb2ppZS5jbi9ob21lLnBocD9tb2Q9c3BhY2UmdWlkPTE0OTc3MTgmZG89dGhyZWFkJnZpZXc9bWUmZnJvbT1zcGFjZQ==" title="https:&#x2F;&#x2F;www.52pojie.cn&#x2F;home.php?mod&#x3D;space&amp;uid&#x3D;1497718&amp;do&#x3D;thread&amp;view&#x3D;me&amp;from&#x3D;space">吾爱破解</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9qdWVqaW4uaW0vdXNlci8yOTk5MTIzNDUyNjI2MzY2" title="https:&#x2F;&#x2F;juejin.im&#x2F;user&#x2F;2999123452626366">掘金</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9zZWdtZW50ZmF1bHQuY29tL3UvbGF6eXRpbWVz" title="https:&#x2F;&#x2F;segmentfault.com&#x2F;u&#x2F;lazytimes">思否</span>
        </li>
    </ul>
  </div>

      </div>

      <div class="wechat_OA">
        <span>欢迎关注我的公众号</span>
        <br>
          <!-- 这里添加你的二维码图片 -->
        <img src ="https://adong-picture.oss-cn-shenzhen.aliyuncs.com/adong/wechat_channel.jpg">
      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">阿东</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">2m</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">29:50</span>
</div>
  <div class="powered-by">由 <span class="exturl theme-link" data-url="aHR0cHM6Ly9oZXhvLmlv">Hexo</span> & <span class="exturl theme-link" data-url="aHR0cHM6Ly90aGVtZS1uZXh0Lm9yZw==">NexT.Gemini</span> 强力驱动
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : true,
      appId      : 'qMUpEEvBgXaMDD1b0ftgi9xr-gzGzoHsz',
      appKey     : 'UCdfT4Rfih6MO6y8DI4fstf6',
      placeholder: "Just go go",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : 'zh-CN' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
